我正在使用Retrofit 2.1.0和OkHttp 3.4.2创建一个应用程序.
在minifyEnabled设置为false的调试模式下,一切都运行良好但只要我将minifyEnabled更改为true,我就会得到以下异常:
HTTP FAILED: java.net.ProtocolException: Too many follow-up requests: 21
Run Code Online (Sandbox Code Playgroud)
我的Proguard OkHttp规则如下:
-keep class com.squareup.okhttp3.** {
*;
}
-dontwarn okhttp3.**
-dontwarn okio.**
Run Code Online (Sandbox Code Playgroud)
我无法理解为什么抛出此异常,我不明白为什么该应用程序似乎正在提出21个跟进请求.谁能帮我?
在proguard.cfg中排除父包后,如何包含某些包:
例如:
-keep com.myapp.**{*; }
我想要proguard来混淆com.myapp.data.**{*; }
我目前正在使用一个使用大量反射的 Android 库。
一旦我启用 proguard 并运行它......它就会崩溃。
为什么?它使用了大量的反射,并且方法仅通过反射调用,因此它们被proguard检测为未使用并在收缩过程中删除,因此NoSuchMethodError抛出aa 。
为什么会发生这种情况?这很容易弄清楚它们在收缩过程中被删除了,因为 proguard 认为它们是未使用的,因此删除了这些代码片段(所有方法)
那么,如何配置 proguard 以避免缩小或混淆整个包?(图书馆)
注意:我不想使用 -dontshrink 选项,因为它要么全有要么全无,我只想避免使用特定的包。
更多信息:
运行时错误如下:
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.my.app.debug, PID: 3771
java.lang.NoSuchMethodError: observeValueForKeyPath [class java.lang.String, class java.lang.Object, class com.my.lib.util.Dictionary, class java.lang.Object]
at com.my.lib.util.Observable$ObservationManager$Observer.<init>(SourceFile:47)
at com.my.lib.util.Observable$ObservationManager$Observer.<init>(SourceFile:26)
at com.my.lib.util.Observable$ObservationManager.addObserver(SourceFile:159)
...
Run Code Online (Sandbox Code Playgroud)
请注意,问题是一个内部内部类......
我目前的配置是这样的:
-keep,includedescriptorclasses class com.my.** { *; }
-keepclassmembers class com.my.lib** { *; }
-keep,includedescriptorclasses class com.my.lib.util.Observable$* { *; }
-keep,includedescriptorclasses class com.my.lib.util.Observable$*$* { *; }
Run Code Online (Sandbox Code Playgroud)
但这显然只能避免混淆在收缩过程中未删除的方法......我需要避免在收缩过程中删除方法。
我在我的项目中使用 FirebaseFirestore。当我处于调试模式时,minifyEnabled FALSE,应用程序运行得很好,但是当我构建签名的.apk时,minifyEnabled TRUE,它无法按我的预期工作。即它不从 firebase Firestore 加载数据。
我应该写什么 KEEP 语句来排除 FIREBASE FIRESTORE 和 Glide 类的缩小?
dependencies {
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.google.firebase:firebase-core:16.0.9'
implementation 'com.google.firebase:firebase-firestore:19.0.0'
implementation 'com.google.firebase:firebase-ads:17.2.0'
}
Run Code Online (Sandbox Code Playgroud)