johncarl81 / parceler

:package: Android Parcelables made easy through code generation.
http://parceler.org
Apache License 2.0
3.56k stars 273 forks source link

ClassNotFoundException when putExtras on Implicit intent #367

Open doniwinata0309 opened 5 years ago

doniwinata0309 commented 5 years ago

Parceler version : 1.1.12 AGP: 3.3.1

Hi @johncarl81 , I got this runtime error on android system (the activity become crash, but it is crash on android application, and the intent not started. )

Caused by: android.os.BadParcelableException: ClassNotFoundException when unmarshalling: com.test.application.MyParcelObject$$Parcelable
        at android.os.Parcel.readParcelableCreator(Parcel.java:2917)
        at android.os.Parcel.readParcelable(Parcel.java:2843)
        at android.os.Parcel.readValue(Parcel.java:2746)
        at android.os.Parcel.readArrayMapInternal(Parcel.java:3115)
        at android.os.BaseBundle.initializeFromParcelLocked(BaseBundle.java:273)
        at android.os.BaseBundle.unparcel(BaseBundle.java:226)
        at android.os.Bundle.getParcelable(Bundle.java:939)
        at android.content.Intent.getParcelableExtra(Intent.java:7174)
        at com.android.internal.app.ChooserActivity.onCreate(ChooserActivity.java:225)
        at android.app.Activity.performCreate(Activity.java:7051)
        at android.app.Activity.performCreate(Activity.java:7042)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856) 
        at android.app.ActivityThread.-wrap11(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:169) 
        at android.app.ActivityThread.main(ActivityThread.java:6521) 

Turns out this is because i am starting intent chooser (implicit intent) and putExtra Parcelable, that was wrapped by my local object. here the example of code:

        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uriString));
        Parcelable data = Parcels.wrap(new MyParcelObject());

        Intent intentChooser = Intent.createChooser(intent, "title");
        intentChooser.putExtra("test", data);
        getContext().startActivity(intentChooser);

So the error seems to be happen when outside application (intent chooser) trying to unmarshalling the extra, which is wrapped using my internal component MyParcelObject.

Do you know what might be wrong ? Thank you.

johncarl81 commented 5 years ago

Do you have proguard obfuscating class names?

doniwinata0309 commented 5 years ago

Yes i have add them, but, it is also happened on debug version which proguard disabled.

doniwinata0309 commented 5 years ago

Just realize this also happen on other custom that implement parcel object. So seems like it is not parceler bug ?

johncarl81 commented 5 years ago

Strange. It still sounds like an obfuscating problem. Can you view the classes in the apk?

10erlosh commented 5 years ago

Same problem here using Parceler 1.1.12

2019-02-18 16:48:48.410 9977-9977/? E/Parcel: Class not found when unmarshalling: com.example.SomePojo$$Parcelable
    java.lang.ClassNotFoundException: com.example.SomePojo$$Parcelable
        at java.lang.Class.classForName(Native Method)
        at java.lang.Class.forName(Class.java:400)
        at android.os.Parcel.readParcelableCreator(Parcel.java:2489)
        at android.os.Parcel.readParcelable(Parcel.java:2443)
        at android.os.Parcel.readValue(Parcel.java:2346)
        at android.os.Parcel.readArrayMapInternal(Parcel.java:2698)
        at android.os.BaseBundle.unparcel(BaseBundle.java:269)
        at android.os.BaseBundle.getStringArrayList(BaseBundle.java:1114)
        at android.os.Bundle.getStringArrayList(Bundle.java:962)
        at com.huawei.android.internal.app.HwResolverActivity$ResolveListAdapter.<init>(HwResolverActivity.java:1227)
        at com.huawei.android.internal.app.HwResolverActivity.onCreate(HwResolverActivity.java:373)
        at com.huawei.android.internal.app.HwChooserActivity.onCreate(HwChooserActivity.java:80)
        at android.app.Activity.performCreate(Activity.java:6910)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2746)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2864)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1567)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:156)
        at android.app.ActivityThread.main(ActivityThread.java:6577)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:941)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:831)
     Caused by: java.lang.ClassNotFoundException: com.example.SomePojo$$Parcelable
        at java.lang.Class.classForName(Native Method)
        at java.lang.BootClassLoader.findClass(ClassLoader.java:1346)
        at java.lang.BootClassLoader.loadClass(ClassLoader.java:1406)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at java.lang.Class.classForName(Native Method) 
        at java.lang.Class.forName(Class.java:400) 
        at android.os.Parcel.readParcelableCreator(Parcel.java:2489) 
        at android.os.Parcel.readParcelable(Parcel.java:2443) 
        at android.os.Parcel.readValue(Parcel.java:2346) 
        at android.os.Parcel.readArrayMapInternal(Parcel.java:2698) 
        at android.os.BaseBundle.unparcel(BaseBundle.java:269) 
        at android.os.BaseBundle.getStringArrayList(BaseBundle.java:1114) 
        at android.os.Bundle.getStringArrayList(Bundle.java:962) 
        at com.huawei.android.internal.app.HwResolverActivity$ResolveListAdapter.<init>(HwResolverActivity.java:1227) 
        at com.huawei.android.internal.app.HwResolverActivity.onCreate(HwResolverActivity.java:373) 
        at com.huawei.android.internal.app.HwChooserActivity.onCreate(HwChooserActivity.java:80) 
        at android.app.Activity.performCreate(Activity.java:6910) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2746) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2864) 
        at android.app.ActivityThread.-wrap12(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1567) 
        at android.os.Handler.dispatchMessage(Handler.java:105) 
        at android.os.Looper.loop(Looper.java:156) 
        at android.app.ActivityThread.main(ActivityThread.java:6577) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:941) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:831) 
     Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
2019-02-18 16:48:48.411 9977-9977/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.huawei.android.internal.app, PID: 9977
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.huawei.android.internal.app/com.huawei.android.internal.app.HwChooserActivity}: android.os.BadParcelableException: ClassNotFoundException when unmarshalling: com.example.SomePojo$$Parcelable
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2793)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2864)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1567)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:156)
        at android.app.ActivityThread.main(ActivityThread.java:6577)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:941)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:831)
     Caused by: android.os.BadParcelableException: ClassNotFoundException when unmarshalling: com.example.SomePojo$$Parcelable
        at android.os.Parcel.readParcelableCreator(Parcel.java:2517)
        at android.os.Parcel.readParcelable(Parcel.java:2443)
        at android.os.Parcel.readValue(Parcel.java:2346)
        at android.os.Parcel.readArrayMapInternal(Parcel.java:2698)
        at android.os.BaseBundle.unparcel(BaseBundle.java:269)
        at android.os.BaseBundle.getStringArrayList(BaseBundle.java:1114)
        at android.os.Bundle.getStringArrayList(Bundle.java:962)
        at com.huawei.android.internal.app.HwResolverActivity$ResolveListAdapter.<init>(HwResolverActivity.java:1227)
        at com.huawei.android.internal.app.HwResolverActivity.onCreate(HwResolverActivity.java:373)
        at com.huawei.android.internal.app.HwChooserActivity.onCreate(HwChooserActivity.java:80)
        at android.app.Activity.performCreate(Activity.java:6910)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2746)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2864) 
        at android.app.ActivityThread.-wrap12(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1567) 
        at android.os.Handler.dispatchMessage(Handler.java:105) 
        at android.os.Looper.loop(Looper.java:156) 
        at android.app.ActivityThread.main(ActivityThread.java:6577) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:941) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:831) 
johncarl81 commented 5 years ago

Are you using Proguard? Also, verify the class names in your APK.

10erlosh commented 5 years ago

This happens in debug builds without Proguard. It works well when using explicit intents.

johncarl81 commented 5 years ago

Can you come up with a quick demo app so I can debug?

johncarl81 commented 5 years ago

Hmmm, either that or the Parceler annotation processor isn't running. @doniwinata0309 @10erlosh could you share your build Parceler dependency statements?

10erlosh commented 5 years ago

It turned out that my problem only occurs on a huawei device. As a workaround i wrapped the parcel with a bundle and put the bundle into the implicit intent:

parcel = Parcels.wrap(object);
Bundle b = new Bundle();
b.putParcelable(KEY_EXTRA, parcel);
intent.putExtra(KEY_EXTRA, b);

I can live with that.