如何解决ASM Instrumentation进程无法解析某些类的问题?

问题描述 投票:0回答:2

当我构建应用程序时

./gradlew assembleRelease

然后我收到这个警告:

ASM Instrumentation process wasn't able to resolve some classes, this means that
the instrumented classes might contain corrupt stack frames. Make sure the
dependencies that contain these classes are on the runtime or the provided
classpath. Otherwise, the jvm might fail to load the corrupt classes at runtime
when running in a jvm environment like unit tests.

Classes that weren't resolved:
> sun.misc.Unsafe
> androidx.appcompat.view.ContextThemeWrapper
> com.google.common.util.concurrent.ListenableFuture
> retrofit2.Response
> javax.mail.internet.MimeBodyPart
> javax.naming.NamingException
> javax.naming.directory.Attributes

我目前使用的是 AGP 8.0.1

在之前的 AGP 版本 (7.4.2) 中,警告的措辞有所不同:

Unable to find common super type for java/lang/reflect/Field and sun/misc/Unsafe.
Unable to find common super type for sun/misc/Unsafe and java/lang/Object.
Unable to find common super type for com/google/android/gms/internal/measurement/zznt and sun/misc/Unsafe.
Unable to find common super type for androidx/appcompat/view/ContextThemeWrapper and android/content/Context.
Unable to find common super type for com/google/common/util/concurrent/ListenableFuture and androidx/work/InputMerger.
Unable to find common super type for java/lang/Throwable and retrofit2/Response.
Unable to find common super type for java/lang/Exception and javax/mail/internet/MimeBodyPart.
Unable to find common super type for javax/naming/NamingException and javax/naming/directory/Attributes.
Unable to find common super type for java/lang/Object and javax/naming/directory/Attributes.
Unable to find common super type for java/lang/reflect/Field and sun/misc/Unsafe.
Unable to find common super type for sun/misc/Unsafe and java/lang/Object.
Unable to find common super type for com/google/android/recaptcha/internal/zzjo and sun/misc/Unsafe.
Unable to find common super type for java/lang/reflect/Field and sun/misc/Unsafe.
Unable to find common super type for sun/misc/Unsafe and java/lang/Object.
Unable to find common super type for com/google/android/gms/internal/firebase-auth-api/zzaje and sun/misc/Unsafe.

我怀疑消息更改与https://issuetracker.google.com/issues/231997058有关,但我仍然不知道如何解决此警告

android gradle android-gradle-plugin
2个回答
2
投票

我是这个问题的原始记者,我认为作为用户,你没有什么可做的。一些库将其依赖项声明为

compileOnly
,并且当 ASM 工具尝试解析这些
compileOnly
依赖项中的类型(而它们在运行时不存在)时,会打印此警告。

但是,如果声明

compileOnly
依赖项的库具有适当的运行时检查,甚至不会从该依赖项中调用类(如果它不存在于类路径中),那么这本身没有问题。

但我认为可能值得在 google tracker 上 ping 这个问题,因为我也认为打印此警告没有意义,尤其是在这样的情况下

Unable to find common super type for sun/misc/Unsafe and java/lang/Object.

0
投票

我最近也遇到了这个问题,我一直在努力确保列表中的大多数都是我添加为

implementation
的依赖项,这已将数量减少到我拥有的最后 3 个剩余。

Classes that weren't resolved:
> sun.misc.Unsafe
> javax.naming.NamingException
> javax.naming.directory.Attributes

其他人我已经搜索了找到这些类的 jar 文件,并在需要时添加了它们。有些可以在添加到应用程序的库中找到,我也添加了这些依赖项。使用

minify
将删除任何未使用的内容,如果
minify
使用
proguard
配置删除它们,您可以保留所需的内容。

© www.soinside.com 2019 - 2024. All rights reserved.