Proguard R8 warnings
Asked Answered
G

3

14

Getting these warning while using r8

Missing class org.bouncycastle.jsse.BCSSLParameters (referenced from: void okhttp3.internal.platform.BouncyCastlePlatform.configureTlsExtensions(javax.net.ssl.SSLSocket, java.lang.String, java.util.List) and 1 other context)
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>())

Tried using this but it did not work.

-keep class com.squareup.okhttp.** { *; }
Gemstone answered 16/9, 2022 at 18:25 Comment(1)
which jdk did you use?Merous
P
19

Actually this seems to be now fixed in OkHttp version 4.11.0, released on April 2023: https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp-bom

I had the same issue and once I updated to this version, the build goes through successfully

Pasol answered 26/4, 2023 at 17:18 Comment(1)
I had the same problem, after 2 days of trying, I downgraded OkHttp from version 5.0.0-alpha.1 to version 4.12.0 and the problem was solved. I am very surprised.Virginia
A
10

Fixed in okhttp 5 https://github.com/square/okhttp/issues/6258

Add rulse from https://raw.githubusercontent.com/square/okhttp/master/okhttp/src/jvmMain/resources/META-INF/proguard/okhttp3.pro

-dontwarn org.conscrypt.**
-dontwarn org.bouncycastle.**
-dontwarn org.openjsse.**
Achilles answered 31/12, 2022 at 19:17 Comment(1)
It is not working for meOutmaneuver
P
1

Missing classes when compiling with R8 means that there are references to these classes in the input, but they have no definition in the input neither in the program itself, on the classpath or in the library/bootclasspath (android.jar when building Android apps). The -keep rule is used to keep classes already present in the input, and has no effect on missing classes (it might actually end up giving more missing classes).

To silence the warnings about missing classes the -dontwarn directive can be used, e.g.:

-dontwarn org.bouncycastle.jsse.BCSSLParameters

Before going ahead with adding -dontwarn make sure that the missing classes are not due to a missing dependency, which might end up causing runtime failures.

Professed answered 19/9, 2022 at 6:49 Comment(3)
This seems the most informative answer. However, -dontwarn org.bouncycastle.jsse.BCSSLParameters shows up in red in Android Studio, with "Unresolved class name" complaint. Using ** avoids this problem and you end up with much cleaner proguard file, with just one -dontwarn line per library. For example: -dontwarn org.bouncycastle.**Lighter
Yes, the red squiggles under a -dontwarn class might not be the best UI, as -dontwarn is often used for classes which are missing. I have opened issuetracker.google.com/328166444 on this issue.Professed
The issue with the squiggles was already fixed in Android Studio Iguana, issuetracker.google.com/301246673.Professed

© 2022 - 2024 — McMap. All rights reserved.