Hello all. I’m facing a problem with Kotlin 2.0 an...
# android
m
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:
Copy code
buildConfigField("boolean", "BUILD_VALUE", "false")
Then in a sample activity I show the value
Copy code
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
Copy code
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
👀 2
I have tried with values in an object file instead BuildConfig and it works fine. The issue happens only with BuildConfig fields
s
That might be and issue with Live Edit feature, which is enabled by default in Android Studio. Try to disable it in the settings and see if it helps
m
Just checked and I have Live Edit off. Moreover, in my sample I’ve used composed to check the value, but the issue is not related to compose.
u
Hey, Im having the same problem. Have you found any solution for this? Im thinking about reverting to kotlin 1.9 or something to replace buildConfigField.
m
👀 1
We have reverted to 1.9.3 for now.
👍 1
u
Thank you for sharing 🙏
178 Views