davehenry
davehenry

Reputation: 1076

How to set build variant config fields and resource values in Android Studio 3.0?

Android Studio 3.0 and the associated gradle plugin update have removed the gradle build variant API. Does anyone know how to achieve functionality similar to what i've written below with AS 3.0 and gradle 4.0?

applicationVariants.all { variant ->
   variant.buildConfigField "String", "SEARCH_SUGGESTION_PROVIDER_AUTHORITY", "\"" + variant.applicationId + ".providers.SearchSuggestionProvider\""
   variant.resValue "string", "account_type", "\"" + variant.applicationId + ".account\""
}

Upvotes: 2

Views: 591

Answers (1)

Grisgram
Grisgram

Reputation: 3253

Read the documentation about flavors and flavor dimensions.

https://developer.android.com/studio/build/build-variants

https://proandroiddev.com/advanced-android-flavors-part-2-enter-flavor-dimensions-4ad7f486f6

it can look like this:

    flavorDimensions "branding"

//
// For each app edition we need one explicit flavor that sets id and signingConfig
//
productFlavors {

    home {
        dimension "branding"
        applicationId "com.example.home"
        signingConfig signingConfigs.home
    }

    free {
        dimension "branding"
        applicationId "com.example.free"
        signingConfig signingConfigs.free
    }

    full {
        dimension "branding"
        applicationId "com.example.full"
        signingConfig signingConfigs.full
    }

}

There are almost all things possible for each flavor in each dimension.

Hope this helps.

Regarding the resource values:

We here solve this by creating source sets (home, full, free) and set the variant-specific resources in each of the source sets.

Upvotes: 1

Related Questions