使用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
添加排除规则对我来说似乎不正确。
3条答案
按热度按时间xoefb8l81#
同时,我可以自己解决这个问题。对于其他面临这个问题的人。下面是我现在使用的解决方法:
基于下面的dicussion和OkHttp库本身上的这个pull request,我在我的
proguard-rules.pro
文件中添加了以下规则:hjzp0vay2#
这些消息可能是在升级到AGP 8.0.0之前的警告。从7.0.0开始,添加了缺少类的警告,并宣布了使它们出错的计划。
另请参阅https://issuetracker.google.com/278765639,其中报告了此问题。
文件
app/build/outputs/mapping/release/missing_rules.txt
是由AGP生成的,其中包含避免编译错误所需的-dontwarn
指令。b4lqfgs43#
只需在Gradle文件中添加以下代码:
在此之后,尝试构建发布版本,转到app/build/outputs/mapping并在proguard文件中添加所有带有-dontwarn的行
对我来说是下面几行: