带有 Kotlin 1.8.20 的 Android Gradle 插件 8.0.0 导致 OkHttp3 R8 缩小问题

问题描述 投票:0回答:1

使用 Android Gradle Plugin (AGP) 8.0.0 升级到 Kotlin 1.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
中添加排除规则在这一点上对我来说似乎不正确。

android kotlin android-gradle-plugin proguard android-r8
1个回答
0
投票

同时我可以自己解决问题。对于其他面临此问题的人。这是我现在使用的解决方法:

基于以下讨论和OkHttp库本身的拉取请求,我将以下规则添加到我的

proguard-rules.pro
文件中:

-dontwarn okhttp3.internal.platform.**
-dontwarn org.conscrypt.**
-dontwarn org.bouncycastle.**
-dontwarn org.openjsse.**
-dontwarn org.slf4j.impl.StaticLoggerBinder
© www.soinside.com 2019 - 2024. All rights reserved.