Search code examples
androidproguardandroid-r8android-14

What is the potential issue with ProGuard and ClassValue on Android 14?


In the documentation for behaviour changes when targeting Android 14, there is an issue mentioned related to ProGuard and ClassValue:

ProGuard issues: In some cases, the addition of the java.lang.ClassValue class causes an issue if you try to shrink, obfuscate, and optimize your app using ProGuard. The problem originates with a Kotlin library that changes runtime behaviour based on whether Class.forName("java.lang.ClassValue") returns a class or not. If your app was developed against an older version of the runtime without the java.lang.ClassValue class available, then these optimizations might remove the computeValue method from classes derived from java.lang.ClassValue.

From the very little information given, I'm struggling to understand exactly what this means and the potential impact - and can't find more detail anywhere. The "Kotlin library" is not named, but I think it may be kotlinx.serialization, based on this issue I found - if so, then the "change in runtime behaviour" is just about more efficient caching. I also don't know what is meant by "the runtime" (is this Android version (actual/target)? Compile-time JDK version? Proguard/R8 version? Library version?)

If I developed an app which targeted an earlier version of Android, then obviously I won't have any classes which extend from java.lang.ClassValue, because that class didn't exist. So how could I face a problem with the overridden computeValue method when changing to target Android 14?

(By the way, when it says "ProGuard" I'm assuming this relates to R8 as well, not only ProGuard itself, although that's not explicitly clear from the docs.)


Solution

  • All the details are in the issue you referenced, and the [issue should be fixed], so you should ensure you use a version of kotlinx.serialization with the fix.

    The underlying issue is that R8 can remove the computeValue method when compiling with a compileSdk of 33 and below, as java.lang.ClassValue is not present in android.jar so ``computeValue` is not seen as a library override.

    You can move to a compileSdk of 34 to get a library with java.lang.ClassValue, see https://developer.android.com/about/versions/14/setup-sdk.