pusher / push-notifications-android

Android SDK for Pusher Beams
https://www.pusher.com/beams
MIT License
22 stars 22 forks source link

Runtime crash with moshi 1.9.x #100

Closed bmoliveira closed 4 years ago

bmoliveira commented 4 years ago

Hey 👋

I was trying to update all libs to the latest version on my project and after all the updates, I've started to get a crash on runtime with the serialization of the class com.pusher.pushnotifications.internal.StartJob

Not 100% sure but I think the crash comes to the fact that on Moshi 1.9.+ some implicit behaviours changed.

I've found this article and I think it's related to this https://www.zacsweers.dev/a-closer-look-at-moshi-1-9/

But here it is the crash I'm getting:

2019-12-06 08:21:49.315 7481-7481/ E/AndroidRuntime: FATAL EXCEPTION: main
    Process: , PID: 7481
    java.lang.RuntimeException: Unable to get provider com.pusher.pushnotifications.internal.PushNotificationsInitProvider: java.lang.IllegalArgumentException: Cannot serialize Kotlin type com.pusher.pushnotifications.internal.StartJob. Reflective serialization of Kotlin classes without using kotlin-reflect has undefined and unexpected behavior. Please use KotlinJsonAdapter from the moshi-kotlin artifact or use code gen from the moshi-kotlin-codegen artifact.
    for class com.pusher.pushnotifications.internal.StartJob
    for class com.pusher.pushnotifications.internal.ServerSyncJob
        at android.app.ActivityThread.installProvider(ActivityThread.java:6988)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:6528)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6445)
        at android.app.ActivityThread.access$1300(ActivityThread.java:219)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1859)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
     Caused by: java.lang.IllegalArgumentException: Cannot serialize Kotlin type com.pusher.pushnotifications.internal.StartJob. Reflective serialization of Kotlin classes without using kotlin-reflect has undefined and unexpected behavior. Please use KotlinJsonAdapter from the moshi-kotlin artifact or use code gen from the moshi-kotlin-codegen artifact.
    for class com.pusher.pushnotifications.internal.StartJob
    for class com.pusher.pushnotifications.internal.ServerSyncJob
        at com.squareup.moshi.Moshi$LookupChain.exceptionWithLookupStack(Moshi.java:349)
        at com.squareup.moshi.Moshi.adapter(Moshi.java:150)
        at com.squareup.moshi.Moshi.adapter(Moshi.java:98)
        at com.squareup.moshi.Moshi.adapter(Moshi.java:68)
        at com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory.create(PolymorphicJsonAdapterFactory.java:162)
        at com.squareup.moshi.Moshi.adapter(Moshi.java:138)
        at com.squareup.moshi.Moshi.adapter(Moshi.java:98)
        at com.squareup.moshi.Moshi.adapter(Moshi.java:72)
        at com.pusher.pushnotifications.internal.ServerSyncHandler$Companion.obtain$pushnotifications_release(ServerSyncHandler.kt:77)
        at com.pusher.pushnotifications.PushNotificationsInstance$serverSyncHandler$1.invoke(PushNotificationsInstance.kt:106)
        at com.pusher.pushnotifications.PushNotificationsInstance$serverSyncHandler$1.invoke(PushNotificationsInstance.kt:93)
        at com.pusher.pushnotifications.PushNotificationsInstance.<init>(PushNotificationsInstance.kt:105)
        at com.pusher.pushnotifications.internal.PushNotificationsInitProvider.onCreate(ApplicationLifecycle.kt:67)
        at android.content.ContentProvider.attachInfo(ContentProvider.java:2092)
        at android.content.ContentProvider.attachInfo(ContentProvider.java:2066)
        at android.app.ActivityThread.installProvider(ActivityThread.java:6983)
            ... 10 more
     Caused by: java.lang.IllegalArgumentException: Cannot serialize Kotlin type com.pusher.pushnotifications.internal.StartJob. Reflective serialization of Kotlin classes without using kotlin-reflect has undefined and unexpected behavior. Please use KotlinJsonAdapter from the moshi-kotlin artifact or use code gen from the moshi-kotlin-codegen artifact.
        at com.squareup.moshi.ClassJsonAdapter$1.create(ClassJsonAdapter.java:83)
        at com.squareup.moshi.Moshi.adapter(Moshi.java:138)
            ... 24 more

Thank you

julioromano commented 4 years ago

This is due to a breaking change in Moshi 1.9.0: https://github.com/square/moshi/blob/master/CHANGELOG.md#version-190

Now the KotlinJsonAdapterFactory must be explicitly added when building the Moshi instance.

bmoliveira commented 4 years ago

Yup, it was exactly that, thank you.

Do you know if there is any planned for this merge and release?

daniellevass commented 4 years ago

Hi All,

Thanks for raising! We've just released version 1.6.0 of the library which upgrades our dependency of moshi to 1.9 to work with others who have also already upgraded!

Please re-open or raise a new issue if this issue persists :-)