5

When I run my project from debug everything works fine. However when I run it with the signed apk I generated from Android Studio (using proguard), I get the following errors when using getParcelable:

java.lang.RuntimeException: Unable to start activity ComponentInfo{mypackage.android/mypackage.mobile.android.activities.searchActivity}: android.os.BadParcelableException: Parcelable protocol requires a Parcelable.Creator object called  CREATOR on class mypackage.android.a.d.a

Why does this exception happen only with my signed apk? In my proguard config file I did have to use dontwarn android.support.v4.** to avoid proguard errors. Is that coming back to bite me?

4

2 回答 2

12

您需要保护CREATOR字段免受 proguard 的混淆

将此行添加到您的 proguard 配置中:

-keep class * implements android.os.Parcelable { 
   public static final android.os.Parcelable$Creator *; 
}
于 2013-10-09T15:06:23.693 回答
0

对于新手,如果您忘记定义您的 CREATOR 字段 final,也会发生这种情况

public static final Parcelable.Creator CREATOR
于 2019-01-14T07:27:14.667 回答