Search code examples
androidkotlinandroid-gradle-pluginproguardandroid-r8

Android Gradle Plugin 8.0.0 with Kotlin 1.8.20 causes OkHttp3 R8 minify problem


After upgrading to Kotlin 1.8.20 with Android Gradle Plugin (AGP) 8.0.0, I suddendly get the following error messages when running the :app:minifyProdWithR8 Gradle task :

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)

I have the Ktor client library io.ktor:ktor-client-android:2.2.4 in my project which probably depends on okhttp3 and the other missing classes. Has anyone else experience that problem?

Just adding exclusion rules to the proguard-rules.pro doesn't seem right to me at this point.


Solution

  • Meanwhile I could solve the problem by myself. For anyone else facing this problem. Here is the workaround I am using now:

    Based on the following dicussion and this pull request on the OkHttp Library itself, I added the following rules to my proguard-rules.pro file:

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