[英]okhttp3 minifyEnabled causes crash on Android 4.1.2
This code in okhttp:3.12.13
works fine with minifyEnabled false
okhttp:3.12.13
中的这段代码在 minifyEnabled minifyEnabled false
下工作正常
private static boolean supportsAlpn() {
if (Security.getProvider("GMSCore_OpenSSL") != null) {
return true;
} else {
try {
Class.forName("android.net.Network"); //NoClassDefFoundError here if minifyEnabled true
return true;
} catch (ClassNotFoundException ignored) { }
}
return false;
}
but with minifyEnabled true
the following error occurs on Android 4.1.2但是使用
minifyEnabled true
在 Android 4.1.2 上会出现以下错误
Caused by: java.lang.ExceptionInInitializerError
at okhttp3.OkHttpClient.newSslSocketFactory(OkHttpClient.java:292)
at okhttp3.OkHttpClient.<init>(OkHttpClient.java:258)
at okhttp3.OkHttpClient.<init>(OkHttpClient.java:231)
Caused by: java.lang.ExceptionInInitializerError
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:217)
at java.lang.Class.forName(Class.java:172)
at okhttp3.internal.platform.AndroidPlatform.supportsAlpn(AndroidPlatform.java:219)
at okhttp3.internal.platform.AndroidPlatform.buildIfSupported(AndroidPlatform.java:262)
at okhttp3.internal.platform.Platform.findAndroidPlatform(Platform.java:246)
at okhttp3.internal.platform.Platform.findPlatform(Platform.java:202)
at okhttp3.internal.platform.Platform.<clinit>(Platform.java:78)
Caused by: java.lang.NoClassDefFoundError
at android.net.Network.<clinit>(Unknown Source)
What lines should be added to Proguard
to avoid the crash?应该在
Proguard
中添加哪些行以避免崩溃?
Edit: Adding rules 1 and 2 didn't help.编辑:添加规则1和2没有帮助。
These rules worked, but apk size gets increased by 0.6 MB. 这些规则有效,但 apk 大小增加了 0.6 MB。
-keepattributes Signature
-keepattributes *Annotation*
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-dontwarn okhttp3.**
I'm wondering if it is possible to fix the issue without keeping all okhttp3
classes in the apk.我想知道是否可以在不将所有
okhttp3
类保留在 apk 中的情况下解决此问题。
Just get rules from below files/links只需从以下文件/链接中获取规则
https://raw.githubusercontent.com/square/okhttp/master/okhttp/src/jvmMain/resources/META-INF/proguard/okhttp3.pro https://github.com/square/okio/blob/master/okio/src/jvmMain/resources/META-INF/proguard/okio.pro https://raw.githubusercontent.com/square/okhttp/master/okhttp/src/jvmMain/resources/META-INF/proguard/okhttp3.pro https://github.com/square/okio/blob/master/okio /src/jvmMain/resources/META-INF/proguard/okio.pro
Refer https://square.github.io/okhttp/features/r8_proguard/参考https://square.github.io/okhttp/features/r8_proguard/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.