2

在我的 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 被禁用并且其他一切保持不变,我在运行时不会遇到此错误。

4

2 回答 2

1

你需要保持sun.misc.Unsafe

-keep class sun.misc.Unsafe { *; }
-dontnote sun.misc.Unsafe

或者,一个规则includedescriptorclasses应该动态地保持它:

-keep,includedescriptorclasses class com.google.common.**

一般来说:

  • 添加 switch-verbose对编写 ProGuard 配置规则很有帮助。

  • 添加开关-dontoptimize可用于禁用所有优化,以进行测试。

刚发现这个

R8 现在理解 META-INF/proguard 中的 proguard 规范。

但除非已添加此内容,否则必须添加自定义规则 - 而不是使用消费者规则。

于 2018-12-15T21:48:08.033 回答
0

在您的项目保护文件中。请添加以下内容:

-keepnames class com.google.common.**

-keep class com.google.common.**

-dontwarn com.google.common.**

这似乎是一种错误。但有时当您使用 D8 时,它往往会重命名类名或完全删除它们。

于 2018-12-10T14:26:46.633 回答