相关文章推荐
讲道义的花卷  ·  vue3 + ...·  2 年前    · 
怕老婆的课本  ·  Android.os.badparcelab ...·  2 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Android BadParcelableException(Parcelable protocol requires a Parcelable.Creator object called CREATOR) only with signed apk

Ask Question

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?

proguard f** up CREATOR field of your class ... you have to "tell" progroud to not tuch this filed in your class – Selvin Oct 9, 2013 at 14:42 -keep class * implements android.os.Parcelable { public static final android.os.Parcelable$Creator *; } – Selvin Oct 9, 2013 at 14:43

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 *; 
                hmmm, they added such thing in defualt proguard settings: ANDROID_SDK\tools\proguard\proguard-android.txt ... so if you are using proguard with gradle "in normal way" you shouldn't worry about this anymore (by normal way i mean proguardFiles getDefaultProguardFile('proguard-android.txt'), your_specific_files_go_here.pro
– Selvin
                Mar 10, 2015 at 9:49
                For those that might be seeing a similar issue as of late, as I am, this is already included by default in all the proguard files, which are now at …\AndroidStudioProjects\<app name>\app\build\intermediates\proguard-files.  So, this answer might not be helpful for us.
– Bink
                Dec 28, 2021 at 22:33
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.