升级 Android Gradle 插件至 8.0.2 后,使用 R8 压缩 Android 应用时出现错误。

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

Error when minifying Android app with R8 after upgrading Android Gradle Plugin to 8.0.2

问题

我最近将我的Android应用项目中的Android Gradle插件从版本7.4.2升级到了8.0.2。然而,在执行minifyReleaseWithR8任务时,我现在遇到了一个错误。

我收到的错误消息如下:

Task :app:minifyReleaseWithR8
AGPBI: {"kind":"error","text":"Library class android.test.AndroidTestRunner extends program class junit.runner.BaseTestRunner","sources":[{}],"tool":"R8"}
Library class android.test.AndroidTestRunner extends program class junit.runner.BaseTestRunner

AGPBI: {"kind":"error","text":"Library class android.test.InstrumentationTestCase extends program class junit.framework.TestCase","sources":[{}],"tool":"R8"}
Library class android.test.InstrumentationTestCase extends program class junit.framework.TestCase

Task :app:minifyReleaseWithR8 FAILED

这个错误似乎与缺少服务类和库类与程序类之间的冲突有关。

只有在我更新了Android Gradle插件后才开始出现这些错误。我尝试过清理项目并确保所有依赖项都是最新的,但问题仍然存在。

是否还有其他人在升级到Android Gradle插件8.0.2时遇到类似的问题?我该如何解决这些错误并成功地使用R8缩小我的发布构建?

任何帮助或建议将不胜感激。谢谢!

英文:

I recently upgraded the Android Gradle Plugin in my Android app project from version 7.4.2 to 8.0.2. However, I'm now encountering an error during the release build when the minifyReleaseWithR8 task is executed.

The error message I'm getting is as follows:

Task :app:minifyReleaseWithR8
AGPBI: {"kind":"error","text":"Library class android.test.AndroidTestRunner extends program class junit.runner.BaseTestRunner","sources":[{}],"tool":"R8"}
Library class android.test.AndroidTestRunner extends program class junit.runner.BaseTestRunner

AGPBI: {"kind":"error","text":"Library class android.test.InstrumentationTestCase extends program class junit.framework.TestCase","sources":[{}],"tool":"R8"}
Library class android.test.InstrumentationTestCase extends program class junit.framework.TestCase

Task :app:minifyReleaseWithR8 FAILED

The error seems to be related to missing service classes and conflicts between library classes and program classes.

These errors only started occurring after I updated the Android Gradle Plugin. I've tried cleaning the project and ensuring that all dependencies are up to date, but the issue persists.

Has anyone else encountered a similar issue when upgrading to Android Gradle Plugin 8.0.2? How can I resolve these errors and successfully minify my release build with R8?

Any help or suggestions would be greatly appreciated. Thank you!

答案1

得分: 1

我们通过将以下内容添加到 app/proguard-rules.pro 中来解决了这个问题:

-dontwarn com.squareup.okhttp.CipherSuite
-dontwarn com.squareup.okhttp.ConnectionSpec
-dontwarn com.squareup.okhttp.TlsVersion

似乎一些混淆警告被视为错误。

英文:

We fixed the problem by adding

-dontwarn com.squareup.okhttp.CipherSuite
-dontwarn com.squareup.okhttp.ConnectionSpec
-dontwarn com.squareup.okhttp.TlsVersion

to the app/proguard-rules.pro.

It seems like some minification warnings were treated as errors.

huangapple
  • 本文由 发表于 2023年6月13日 15:05:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76462410.html
匿名

发表评论

匿名网友

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

确定