如何解决 ASM 仪器化过程无法解析某些类?

huangapple go评论69阅读模式
英文:

How to solve ASM Instrumentation process wasn't able to resolve some classes?

问题

When I build the app
./gradlew assembleRelease
then I get this warning:

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

I'm currently using AGP 8.0.1

In the previous AGP version (7.4.2), the warning was worded differently:

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.

I suspect the message change is related to https://issuetracker.google.com/issues/231997058 but I still have no idea how to fix this warning

英文:

When I build the app
./gradlew assembleRelease
then I get this warning:

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

I'm currently using AGP 8.0.1

In the previous AGP version (7.4.2), the warning was worded differently:

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.

I suspect the message change is related to https://issuetracker.google.com/issues/231997058 but I still have no idea how to fix this warning

答案1

得分: 1

我是这个问题的最初报告人,我认为作为用户,你的一方面不需要太多的操作。一些库将它们的依赖项声明为compileOnly,而在ASM插装尝试从这些compileOnly依赖项中解析类型时,会打印此警告,但在运行时这些依赖项并不存在。

但从本质上讲,如果声明compileOnly依赖项的库具有适当的运行时检查来避免调用来自该依赖项的类,如果它不在类路径中存在的话,这并没有什么问题。

但我认为也许值得在Google跟踪器上提及此问题,因为我还认为在类似于

无法找到sun/misc/Unsafe和java/lang/Object的公共超类型。

这种情况下打印这个警告是没有意义的。

英文:

I was the original reporter of this issue and I think there's not much to do from your side as a user. Some of the libraries declare their dependencies as compileOnly and this warning is printed when ASM instrumentation is trying to resolve types from those compileOnly dependencies while they are not present at runtime.

But there's nothing wrong with that per se, if the library declaring compileOnly dependency has proper runtime checks to not even call to the classes from that dependency, if it's not present on the classpath.

But I think it might be worth pinging that issue on google tracker because I also think this doesn't make sense to print this warning, especially in the case like

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

huangapple
  • 本文由 发表于 2023年5月17日 21:10:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76272487.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定