简体   繁体   English

okhttp3 minifyEnabled 导致 Android 4.1.2 崩溃

[英]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.编辑:添加规则12没有帮助。

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 中的情况下解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM