Android BadParcelableException only with signed apk

这一生的挚爱 提交于 2019-12-18 06:46:42

问题


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?


回答1:


You need to protect CREATOR fields from proguard's obfuscation

add this lines to your proguard config:

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



回答2:


For new comers, this also happens if you forget to define your CREATOR field final

public static final Parcelable.Creator CREATOR


来源:https://stackoverflow.com/questions/19274974/android-badparcelableexception-only-with-signed-apk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!