user40797 user40797 - 2 years ago 126
Android Question

Wrong build variant

I have 2 modules in my app, one for the api, one for the app.
in the api module I define 2 api endpoint depending if the api is compiled in debug or release:

buildTypes {
all {
buildConfigField "String", "API_DEVICE_TYPE", "\"android-phone\""

debug {
buildConfigField "String", "API_ENDPOINT", "\"\""

release {
buildConfigField "String", "API_ENDPOINT", "\"\""
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), ''

In Android Studio's Build variant panel I selected the debug variant for both app and api module. But when I press play/clean/rebuild/remove all build directory by hand/resync gradle, well whatever I do this is the release api which get compiled everytime.
Any hint ?

Tried with gradle build tools 2.1.0 and 2.2.0-aplha3

Answer Source

Just add this code in your submodule build.gradle

// There is a limitation in gradle: You can't pick what submodule of app you want to compile your app with.
// This attribut define which build variant you want your api to be compiled against.
defaultPublishConfig "debug"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download