user40797 user40797 - 5 months ago 10
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", "\"https://beta-api.company.com/\""
}

release {
buildConfigField "String", "API_ENDPOINT", "\"https://api.company.com/\""
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}


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

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.
// https://sites.google.com/a/android.com/tools/tech-docs/new-build-system/user-guide#TOC-Library-Publication
defaultPublishConfig "debug"
Comments