启用Proguard时Android应用程序崩溃 [英] Android app crashes when Proguard is enabled

查看:167
本文介绍了启用Proguard时Android应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我从eclipse导出签名应用程序并将apk文件安装到我的手机上时,应用程序都会崩溃。这仅在启用Proguard时发生。

Every time I Export Signed Application from eclipse and install the apk file onto my phone, the app would crash. This only happens with Proguard enabled.

这是我的proguard文件

Here is my proguard file

-libraryjars /libs/firebase-client-android-2.2.3.jar
-libraryjars /libs/android-support-v4.jar
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

-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.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
-keep public class * implements java.io.Serializable
-keep public class * extends android.support.v4.app.Fragment
-keep public class * extends android.support.v4.app.ListFragment

-dontwarn com.shaded.fasterxml.**
-dontwarn org.apache.**
-dontwarn org.shaded.apache.**
-keepnames class com.shaded.fasterxml.jackson.** { *; }
-keepnames class org.shaded.apache.**

-keepnames interface com.fasterxml.jackson.** { 
    *; 
}

-keep public class * extends com.android.partysearch.ChatApplication
-keepclassmembers class * extends com.android.partysearch.ChatApplication{
 public <init>(android.content.Context);
}


-keep public class org.spongycastle.** {
  <fields>;
  <methods>;
}

-keep public class org.apache.** {
  <fields>;
  <methods>;
}

-ignorewarnings

-keepclasseswithmembernames class * {
    native <methods>;
}

-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.app.Activity {
   public void *(android.view.View);
}


-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}

-keepclassmembers class * implements java.io.Serializable {
    static final long serialVersionUID;
    private static final java.io.ObjectStreamField[] serialPersistentFields;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();
}

我运行了adb logcat命令来检查崩溃报告。以下是我认为重要的报告片段:

I ran the adb logcat command to check the crash report. Here's a snippet of the report that I believe is important:

E/AndroidRuntime(28630): Caused by: java.lang.RuntimeException: Something went wrong, please report to support@firebase.com
E/AndroidRuntime(28630):    at com.firebase.client.core.h.a(Unknown Source)
E/AndroidRuntime(28630):    at com.firebase.client.g.a(Unknown Source)
E/AndroidRuntime(28630):    at com.partysearch.ChatApplication.onCreate(Unknown Source)
E/AndroidRuntime(28630):    at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1024)
E/AndroidRuntime(28630):    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4694)
E/AndroidRuntime(28630):    ... 10 more
E/AndroidRuntime(28630): Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context]
E/AndroidRuntime(28630):    at java.lang.Class.getConstructorOrMethod(Class.java:423)
E/AndroidRuntime(28630):    at java.lang.Class.getConstructor(Class.java:397)
E/AndroidRuntime(28630):    ... 15 more

第二个片段:

W/System.err(  356): Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
W/System.err(  356):    at libcore.io.Posix.open(Native Method)
W/System.err(  356):    at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
W/System.err(  356):    at libcore.io.IoBridge.open(IoBridge.java:393)
W/System.err(  356):    ... 8 more

如果有人可以帮助我,我会非常感谢并接受你的回答。

If anyone can help me, I would be very be thankful and accept your answer.

更新:
所以我将这些添加到我的proguard文件

UPDATE: So I added these to my proguard file

-keepattributes Signature
-keep class com.firebase.** { *; }
-keep class org.apache.** { *; }
-keepnames class javax.servlet.** { *; }
-keepnames class org.ietf.jgss.** { *; }
-dontwarn org.w3c.dom.**
-dontwarn org.joda.time.**
-dontwarn org.ietf.jgss.**

现在我在启用Proguard时遇到了与Jackson相关的错误。如果Proguard被禁用,该应用程序仍然有效。以下是崩溃日志的片段:

and now I got an error related to Jackson when Proguard is enabled. The app still works if Proguard is disabled. Here's the snippet of the crash log:

E/AndroidRuntime( 6032): Caused by: com.shaded.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "time" (class com.partysearch.Room), not marked as ignorable (5 known properties: , "note", "level", "userName", "console", "gametype"])

E/AndroidRuntime( 6032):  at [Source: java.io.StringReader@42664098; line: 1, column: 51] (through reference chain: com.partysearch.Room["time"])

E/AndroidRuntime( 6032):    at com.shaded.fasterxml.jackson.databind.DeserializationContext.reportUnknownProperty(DeserializationContext.java:555)

E/AndroidRuntime( 6032):    at com.shaded.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:708)

E/AndroidRuntime( 6032):    at com.shaded.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:1160)

E/AndroidRuntime( 6032):    at com.shaded.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:315)

E/AndroidRuntime( 6032):    at com.shaded.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:121)

E/AndroidRuntime( 6032):    at com.shaded.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2888)

E/AndroidRuntime( 6032):    at com.shaded.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2034)

E/AndroidRuntime( 6032):    at com.firebase.client.DataSnapshot.getValue(DataSnapshot.java:184)

E/AndroidRuntime( 6032):    ... 13 more


推荐答案

我终于解决了它。这是我忘记添加到我的Proguard文件中的内容。 getter和setter。

I finally solved it. This is what I forgot to add to my Proguard file. The getters and setters.

-keep public class com.example.YourModelClassName {
  public *** get*();
  public void set*(***);
} 

这篇关于启用Proguard时Android应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆