How to create a function that sets applicationId-derived variables for build flavors?

时间:2017-08-04 12:34:28

标签: android gradle android-gradle

I'm not fluent in this so I may be missing something obvious.

Intention: eliminate redundancy in defining variables that are different for each flavor.

Example: Flickr auth callback scheme - different for each flavor, to allow multiple flavors on 1 device without ambiguity as to which app should process the callback.

As defaultConfig stuff is processed BEFORE the flavor, I can't use that. How to define a function to do that? The one below, and a "def varSettingMethod(appId)" I also tried, give me ""Could not find method"

ext.varSettingMethod = { appId ->
    resValue "string", "someString1", "bsCharactersAndNowThe${appId}"
    resValue "string", "someString84", "https://something/${appId}"
}
android {
    productFlavors {
        flavor01 {
            applicationId = appIdBase + ".01"
            varSettingMethod(applicationId)
        }
        flavor31 {
            applicationId = appIdBase + ".31"
            varSettingMethod(applicationId)
        }
    }
}

0 个答案:

没有答案