I'm trying to create a ProductionRelease compile-time constant, so that R8 can omit our debugging codes in the final production apk. I hit a roadblock whereby the BuildConfig.DEBUG is not assignable to a const val.
// MyApplication.kt
companion object {
const val isDebug = BuildConfig.DEBUG
const val isProductionRelease = BuildConfig.FLAVOR == "production" && !BuildConfig.DEBUG
}
Upon further checking, I found out BuildConfig.DEBUG is wrapped with a Boolean.parseBoolean() wrapper.
// BuildConfig.java
/**
* Automatically generated file. DO NOT MODIFY
*/
public final class BuildConfig {
public static final boolean DEBUG = Boolean.parseBoolean("true");
public static final String APPLICATION_ID = "com...";
...
}
Questions here is:
- Why can't I assign a static final boolean to a const val?
- Why BuildConfig.DEBUG can't be generated using true|false directly but have to parse through a
parseBooleanfunction?
