7

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?

Selvin
  • 6,598
  • 3
  • 37
  • 43
Adam Johns
  • 35,397
  • 25
  • 123
  • 176
  • 1
    proguard f** up CREATOR field of your class ... you have to "tell" progroud to not tuch this filed in your class – Selvin Oct 09 '13 at 14:42
  • 1
    `-keep class * implements android.os.Parcelable { public static final android.os.Parcelable$Creator *; }` – Selvin Oct 09 '13 at 14:43
  • Thanks! That worked. Post as answer please so I can accept, and future viewers can see. – Adam Johns Oct 09 '13 at 15:00

2 Answers2

13

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 *; 
}
Selvin
  • 6,598
  • 3
  • 37
  • 43
  • Thanks. I added this to my proguard-project.txt file and it works now. – Adam Johns Oct 09 '13 at 15:07
  • Thanks but such things should've documented by Google! – Sufian Mar 10 '15 at 09:34
  • 1
    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 '15 at 09: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\build\intermediates\proguard-files. So, this answer might not be helpful for us. – Bink Dec 28 '21 at 22:33
0

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

public static final Parcelable.Creator CREATOR
AagitoEx
  • 484
  • 2
  • 8