Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

changing resValue in variant

I have two product flavors and three build types.

buildTypes {
    debug {
        signingConfig signingConfigs.debug
    }
    release {
        signingConfig signingConfigs.release
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
    qa {
        applicationIdSuffix ".qa"
        signingConfig signingConfigs.release
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}

productFlavors {
    old {
        applicationId "com.companyname.old"
        buildConfigField "String", "contentProvider", '"com.companyname.android.mobile.contentprovider"'
        resValue "string", "content_provider_authority", '"com.companyname.android.mobile.contentprovider"'

    }
    new {
        applicationId "com.companyname.new"
        buildConfigField "String", "contentProvider", '"' + applicationId + '.contentprovider"'
        resValue "string", "content_provider_authority", '"' + applicationId + '.contentprovider"'
    }
}

Is there a way I can change the resValue of content_provider_authority based not on product flavor, but for the variant? I want all builds for the product flavor new to use the application id + ".contentprovider" but for our product flavor old, use the hardcoded string if debug or release like shown above, but enhance it to have a different hardcoded string for qa build type.

like image 493
Jason Hocker Avatar asked Jan 14 '15 23:01

Jason Hocker


1 Answers

This code is working for me, thanks to the comment of Selvin

productFlavors {
        red {
            ext {
                googleMapsKey = [debug: "AIza4115643435", release: "AIzaXXXXXXXXXX"]
            }
        }

        blue {
            ext {
                googleMapsKey = [debug: "AIza6363474341", release: "AIzaXXXXXXXXXX"]
            }
        }

        applicationVariants.all { variant ->
            def flavor = variant.productFlavors[0]
            variant.resValue  "string", "google_maps_key", "\"${flavor.ext.googleMapsKey[variant.buildType.name]}\""
        }
    }
like image 55
Pablo Cegarra Avatar answered Oct 16 '22 13:10

Pablo Cegarra