8

我面临着这个特殊的问题,即我的应用程序在生成带有混淆(progaurd)的签名 apk 时一旦启动就会崩溃。我的 progaurd 如下所示:

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider

-keep public class * extends android.view.View {
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
public <init>(android.content.Context, android.util.AttributeSet, int);
public void set*(...);
}

-keepclasseswithmembers class * {
 public <init>(android.content.Context, android.util.AttributeSet);
 }

 -keepclasseswithmembers class * {
 public <init>(android.content.Context, android.util.AttributeSet, int);
 }

-keepclassmembers class * extends android.content.Context {
 public void *(android.view.View);
 public void *(android.view.MenuItem);
 }

-keepclassmembers class * implements android.os.Parcelable {
 static ** CREATOR;
 }

-keepclassmembers class **.R$* {
public static <fields>;
 }


 -keepattributes Exceptions,InnerClasses,Signature

  -keep class com.google.api.client.**
  -keepclassmembers class com.google.api.client.** {
  *;
   }


 -keep class com.google.android.gms.**
 -keepclassmembers class com.google.android.gms.** {
 *;
  }
 -keep class com.google.gson.**
 -keepclassmembers class com.google.gson.** {
 *;
 }



-keep class com.google.api.client.** { *; }
-dontwarn com.google.api.client.*
-keep class org.apache.http.** { *; }
-dontwarn org.apache.http.*

-dontnote org.apache.http.**
-dontwarn java.awt.**
-dontwarn org.postgresql.**

-dontwarn javax.activation.**
-dontnote javax.activation.**

-dontwarn myjava.awt.datatransfer.**
-dontnote myjava.awt.datatransfer.**


-dontwarn com.google.android.gms.**
-keep class com.google.android.gms.**
# The official support library.
-keep class android.support.v4.** { *; }
-keepclassmembers class android.support.v4.** {
 *;
 }
 -keep interface android.support.v4.** { *; }
 -keep class android.support.v7.** { *; }


-keepclassmembers class android.support.v7.** {
*;
}
-keep interface android.support.v7.** { *; }

-keep class org.apache.http.** { *; }
-keepclassmembers class org.apache.http.** {*;}
-dontwarn org.apache.**


-keep class org.codehaus.mojo.animal_sniffer.** { *; }
-keep class java.nio.file.** { *; }
-keep class java.lang.invoke.** { *; }

-keepclassmembers class com.fasterxml.jackson.core.**

-keepclassmembers class org.codehaus.mojo.animal_sniffer.**
-keepclassmembers class java.nio.file.**
-keepclassmembers class java.lang.invoke.**
-enter code here`-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
-keepclasseswithmembers class * {
@retrofit2.http.* <methods>;
}

-keep class android.net.http.** { *; }
-keepclassmembers class android.net.http.** {*;}
-dontwarn android.net.**

我能够生成签名的 apk,但如果启动此应用程序,应用程序崩溃并引发以下错误:

java.lang.NoSuchMethodError: No interface method i()I in class 
Landroid/content/res/XmlResourceParser; or its super classes (declaration of 
'android.content.res.XmlResourceParser' appears in 
/system/framework/framework.jar)
                                                   at 
android.support.v4.content.FileProvider.parsePathStrategy(Unknown Source)
                                                   at 
android.support.v4.content.FileProvider.getPathStrategy(Unknown Source)
                                                   at 
android.support.v4.content.FileProvider.attachInfo(Unknown Source)
                                                   at 
android.app.ActivityThread.installProvider(ActivityThread.java:6762)
                                                   at 
android.app.ActivityThread.installContentProviders(ActivityThread.java:6357)

谁能建议我是否遗漏了 progaurd 文件或任何其他配置中的任何内容(在 build.gradle 中,我提到了 minifyEnabled true 以及 proguard 路径)。

4

2 回答 2

21

您可以使用包含 XmlPullParser 类的 jar 包,所以添加这个可以解决它。

-keep class org.xmlpull.v1.** { *;} -dontwarn org.xmlpull.v1.**

于 2017-04-25T09:48:05.747 回答
0

出于某种原因,当我更改时,这已解决

buildTypes {
    release { ...
     minifyEnabled true
     shrinkResources true
  }}

对此

buildTypes {
    release { ...
     minifyEnabled false
  }}
于 2020-09-18T05:03:32.847 回答