Hello all.
I’m facing a problem with Kotlin 2.0 and
buildConfigField
I’ve added support for buildConfigField to the build.gradle.kt file and declare a BuildConfig sample value like:
buildConfigField("boolean", "BUILD_VALUE", "false")
Then in a sample activity I show the value
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
TestKotlin2Theme {
Text(
modifier = Modifier.fillMaxSize().padding(32.dp),
text = "BuildConfig value: ${getValue()}"
)
}
}
}
}
private fun getValue(): Boolean = BuildConfig.BUILD_VALUE
The value is initially show correctly, but if I change the value in build.gradle
without editing the activity the value shown is the previous one, not the current one.
Investigating the issue, I see that the decompiled activity correctly updates always the value
public final class MainActivityKt {
private static final boolean getValue() {
return true;
}
…
// OR
public final class MainActivityKt {
private static final boolean getValue() {
return false;
}
….
But if the activity file is not edited, it seems that
the linker does not update the newly compiled object