英文:
What is the potential issue with ProGuard and ClassValue on Android 14?
问题
在针对 Android 14 的行为变更文档中提到了与 ProGuard 和 ClassValue 相关的问题:
> ProGuard 问题:在某些情况下,添加 java.lang.ClassValue
类会导致使用 ProGuard 收缩、混淆和优化应用时出现问题。问题源于一个 Kotlin 库,它根据 Class.forName("java.lang.ClassValue")
是否返回一个类来更改运行时行为。如果你的应用是针对没有 java.lang.ClassValue
类可用的旧版运行时开发的,那么这些优化可能会从继承自 java.lang.ClassValue
的类中删除 computeValue
方法。
根据提供的极少信息,我很难准确理解这意味着什么以及可能的影响 - 并且无法在任何地方找到更多详细信息。所谓的“Kotlin 库”没有具体的名称,但我认为它可能是 kotlinx.serialization
,基于我找到的此问题 - 如果是这样的话,那么“运行时行为的变化”只是指更有效的缓存。我也不知道所谓的“运行时”是什么意思(是指 Android 版本(实际/目标)吗?编译时的 JDK 版本?Proguard/R8 版本?库版本?)
如果我开发了一个针对较早版本 Android 的应用,那么显然我不会有任何扩展自 java.lang.ClassValue
的类,因为那个类根本不存在。那么当我将目标改为 Android 14 时,如何可能会遇到对重写的 computeValue
方法的问题呢?
(顺便说一下,当它提到“ProGuard”时,我假设这也与 R8 相关,不仅仅是 ProGuard 本身,尽管文档中没有明确说明。)
英文:
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.)
答案1
得分: 1
所有细节都在您引用的问题中这里,而且问题应该已经修复,所以您应该确保使用带有修复的kotlinx.serialization
版本。
根本问题是,当使用compileSdk
为33或更低版本进行编译时,R8可以删除computeValue
方法,因为java.lang.ClassValue
不包含在android.jar
中,所以computeValue
不被视为库覆盖。
您可以切换到compileSdk
为34,以获得包含java.lang.ClassValue
的库,参见此处。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论