Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClassNotFoundException when putExtras on Implicit intent #367

Open
doniwinata0309 opened this issue Feb 13, 2019 · 10 comments
Open

ClassNotFoundException when putExtras on Implicit intent #367

doniwinata0309 opened this issue Feb 13, 2019 · 10 comments

Comments

@doniwinata0309
Copy link

doniwinata0309 commented Feb 13, 2019

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
Copy link
Owner

Do you have proguard obfuscating class names?

@doniwinata0309
Copy link
Author

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

@doniwinata0309
Copy link
Author

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

@johncarl81
Copy link
Owner

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

@10erlosh
Copy link

10erlosh commented Feb 18, 2019

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
Copy link
Owner

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

@10erlosh
Copy link

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

@johncarl81
Copy link
Owner

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

@johncarl81
Copy link
Owner

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

@10erlosh
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants