在我的android项目中启用D8后,我开始看到以下警告:
/Users/yashasvi/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/27.0.1-android/b7e1c37f66ef193796ccd7ea6e80c2b05426182d/guava-27.0.1-android.jar: D8: Type `sun.misc.Unsafe` was not found, it is required for default or static interface methods desugaring of `void com.google.common.util.concurrent.AbstractFuture$UnsafeAtomicHelper.<clinit>()`
/Users/yashasvi/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/27.0.1-android/b7e1c37f66ef193796ccd7ea6e80c2b05426182d/guava-27.0.1-android.jar: D8: Type `sun.misc.Unsafe` was not found, it is required for default or static interface methods desugaring of `sun.misc.Unsafe com.google.common.cache.Striped64.getUnsafe()`
/Users/yashasvi/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/27.0.1-android/b7e1c37f66ef193796ccd7ea6e80c2b05426182d/guava-27.0.1-android.jar: D8: Type `sun.misc.Unsafe` was not found, it is required for default or static interface methods desugaring of `sun.misc.Unsafe com.google.common.hash.LittleEndianByteArray$UnsafeByteArray.getUnsafe()`
/Users/yashasvi/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/27.0.1-android/b7e1c37f66ef193796ccd7ea6e80c2b05426182d/guava-27.0.1-android.jar: D8: Type `sun.misc.Unsafe` was not found, it is required for default or static interface methods desugaring of `void com.google.common.util.concurrent.AbstractFuture$UnsafeAtomicHelper.<clinit>()`
/Users/yashasvi/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/27.0.1-android/b7e1c37f66ef193796ccd7ea6e80c2b05426182d/guava-27.0.1-android.jar: D8: Type `sun.misc.Unsafe` was not found, it is required for default or static interface methods desugaring of `sun.misc.Unsafe com.google.common.cache.Striped64.getUnsafe()`
/Users/yashasvi/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/27.0.1-android/b7e1c37f66ef193796ccd7ea6e80c2b05426182d/guava-27.0.1-android.jar: D8: Type `sun.misc.Unsafe` was not found, it is required for default or static interface methods desugaring of `sun.misc.Unsafe com.google.common.hash.LittleEndianByteArray$UnsafeByteArray.getUnsafe()`
。
项目构建成功,但是在运行时,我看到这些错误日志,因此,应用程序功能受到影响。
java.lang.AbstractMethodError: abstract method "java.lang.Object com.google.common.base.e.a(java.lang.Object)"
at com.google.common.e.a.i$c.a(SourceFile:1464)
at com.google.common.e.a.i$c.a(SourceFile:1453)
at com.google.common.e.a.i$a.run(SourceFile:1408)
at com.google.common.e.a.l$a.execute(SourceFile:456)
at com.google.common.e.a.i$f.a(SourceFile:153)
at com.google.common.e.a.i.a(SourceFile:1234)
搜索了一阵子之后,我找不到任何有用的东西。请帮忙。
是的,如果禁用了D8并且其他所有内容保持不变,则在运行时不会遇到此错误。
最佳答案
您需要保留sun.misc.Unsafe
:
-keep class sun.misc.Unsafe { *; }
-dontnote sun.misc.Unsafe
或者,带有
includedescriptorclasses
的规则应动态保持它:-keep,includedescriptorclasses class com.google.common.**
一般来说:
添加开关
-verbose
对于编写ProGuard配置规则很有帮助。添加开关
-dontoptimize
可用于禁用所有优化,以进行测试。刚刚发现this:
R8现在了解META-INF / proguard中的proguard规格。
但除非已添加,否则必须添加自定义规则-而不是使用使用者规则。
关于android - D8:未找到“sun.misc.Unsafe”类型,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53665135/