Android Gradle Plugin 8.0.0 withKotlin1.8.20 causes OkHttp3 R8 minify problem

6gpjuf90  于 2023-04-21  发布在  Kotlin
关注(0)|答案(3)|浏览(276)

使用Android Gradle Plugin(AGP)8.0.0升级到Kotlin1.8.20后,我在运行:app:minifyProdWithR8 Gradle任务时突然收到以下错误消息:

Missing class org.bouncycastle.jsse.BCSSLSocket (referenced from: void okhttp3.internal.platform.BouncyCastlePlatform.configureTlsExtensions(javax.net.ssl.SSLSocket, java.lang.String, java.util.List) and 5 other contexts)
Missing class org.bouncycastle.jsse.provider.BouncyCastleJsseProvider (referenced from: void okhttp3.internal.platform.BouncyCastlePlatform.<init>())
Missing class org.conscrypt.Conscrypt$Version (referenced from: boolean okhttp3.internal.platform.ConscryptPlatform$Companion.atLeastVersion(int, int, int))
Missing class org.conscrypt.Conscrypt (referenced from: boolean okhttp3.internal.platform.ConscryptPlatform$Companion.atLeastVersion(int, int, int) and 4 other contexts)
Missing class org.conscrypt.ConscryptHostnameVerifier (referenced from: okhttp3.internal.platform.ConscryptPlatform$DisabledHostnameVerifier)
Missing class org.openjsse.javax.net.ssl.SSLParameters (referenced from: void okhttp3.internal.platform.OpenJSSEPlatform.configureTlsExtensions(javax.net.ssl.SSLSocket, java.lang.String, java.util.List))
Missing class org.openjsse.javax.net.ssl.SSLSocket (referenced from: void okhttp3.internal.platform.OpenJSSEPlatform.configureTlsExtensions(javax.net.ssl.SSLSocket, java.lang.String, java.util.List) and 1 other context)
Missing class org.openjsse.net.ssl.OpenJSSE (referenced from: void okhttp3.internal.platform.OpenJSSEPlatform.<init>())
Missing class org.slf4j.impl.StaticLoggerBinder (referenced from: void org.slf4j.LoggerFactory.bind() and 3 other contexts)

我的项目中有Ktor客户端库io.ktor:ktor-client-android:2.2.4,它可能依赖于okhttp3和其他缺少的类。其他人有没有遇到过这个问题?
在这一点上,仅仅向proguard-rules.pro添加排除规则对我来说似乎不正确。

xoefb8l8

xoefb8l81#

同时,我可以自己解决这个问题。对于其他面临这个问题的人。下面是我现在使用的解决方法:
基于下面的dicussion和OkHttp库本身上的这个pull request,我在我的proguard-rules.pro文件中添加了以下规则:

-dontwarn okhttp3.internal.platform.**
-dontwarn org.conscrypt.**
-dontwarn org.bouncycastle.**
-dontwarn org.openjsse.**
-dontwarn org.slf4j.impl.StaticLoggerBinder
hjzp0vay

hjzp0vay2#

这些消息可能是在升级到AGP 8.0.0之前的警告。从7.0.0开始,添加了缺少类的警告,并宣布了使它们出错的计划。
另请参阅https://issuetracker.google.com/278765639,其中报告了此问题。
文件app/build/outputs/mapping/release/missing_rules.txt是由AGP生成的,其中包含避免编译错误所需的-dontwarn指令。

b4lqfgs4

b4lqfgs43#

只需在Gradle文件中添加以下代码:

packagingOptions {
        resources {
            META-INF/proguard/okhttp3.pro
               }

在此之后,尝试构建发布版本,转到app/build/outputs/mapping并在proguard文件中添加所有带有-dontwarn的行
对我来说是下面几行:

-dontwarn java.lang.management.ManagementFactory
-dontwarn java.lang.management.RuntimeMXBean
  • 我使用的是okhttp日志版本5.0.0-alpha.11

相关问题