I am building a library in Android Studio and wish to have a BuildConfigField boolean, called performance, set to true for performance builds. However, it returns false and I need to fix it.
I followed the normal steps to create the field. My issue arises when performance is set to true in BuildConfig.java, but the Java code executes as if it were false. The library build variant is performance and app variant is debug.
Below is Java code which evaluates performance as false, inside a library file. Furthermore, "BuildConfig.BUILD_TYPE" returns "debug".
if (BuildConfig.performance) {
// do the thing
}
The build.gradle file for the library
android {
buildTypes {
release {}
debug {}
performance {}
// set "performance = true" for performance build type
libraryVariants.all { variant ->
variant.outputs.all {
if (variant.getName().contains("performance")) {
variant.buildConfigField "Boolean", "performance", "true"
} else {
variant.buildConfigField "Boolean", "performance", "false"
}
}
}
}
}
From another SO link, I have tried the following without success
android {
publishNonDefault true
}