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

Notificare failed to launch for Moshi initialization error on Android Gradle Plugin 8.0.2 on minifyEnabled #87

Closed
OvoMaS opened this issue Jun 21, 2023 · 3 comments

Comments

@OvoMaS
Copy link

OvoMaS commented Jun 21, 2023

With minifyEnabled set to true and com.android.tools.build:gradle version 8.0.2, Notificare launch fails because of a initialization error for the Internal Moshi instance; this is the stacktrace:

Failed to launch Notificare.
     re.notifica.internal.network.NetworkException$ParsingException: Unable to parse JSON.
     	at re.notifica.internal.network.request.NotificareRequest$responseDecodable$2.invokeSuspend(NotificareRequest.kt:98)
     	at re.notifica.internal.network.request.NotificareRequest$responseDecodable$2.invoke(NotificareRequest.kt:0)
     	at re.notifica.internal.network.request.NotificareRequest$responseDecodable$2.invoke(NotificareRequest.kt:0)
     	at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:89)
     	at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:169)
     	at kotlinx.coroutines.BuildersKt.withContext(Unknown Source:1)
     	at re.notifica.internal.network.request.NotificareRequest.responseDecodable(NotificareRequest.kt:90)
     	at re.notifica.internal.network.request.NotificareRequest$responseDecodable$1.invokeSuspend(NotificareRequest.kt:0)
     	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
     	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
     	at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
     	at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
     	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
     	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
     	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
     	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
     Caused by: java.lang.IllegalArgumentException: Unexpected signature for public final org.json.JSONObject re.notifica.internal.moshi.JSONObjectAdapter.fromJson(com.squareup.moshi.JsonReader,com.squareup.moshi.JsonAdapter).
     @FromJson method signatures may have one of the following structures:
         <any access modifier> R fromJson(JsonReader jsonReader) throws <any>;
         <any access modifier> R fromJson(JsonReader jsonReader, JsonAdapter<any> delegate, <any more delegates>) throws <any>;
         <any access modifier> R fromJson(T value) throws <any>;

     	at com.squareup.moshi.AdapterMethodsFactory.fromAdapter(AdapterMethodsFactory.java:301)
     	at com.squareup.moshi.AdapterMethodsFactory.get(AdapterMethodsFactory.java:135)
     	at com.squareup.moshi.Moshi$Builder.add(Moshi.java:224)
     	at re.notifica.internal.MoshiKt$moshi$2.invoke(Moshi.kt:22)
     	at re.notifica.internal.MoshiKt$moshi$2.invoke(Moshi.kt:15)
     	at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
     	at re.notifica.internal.MoshiKt.getMoshi(Moshi.kt:15)
     	at re.notifica.internal.network.request.NotificareRequest$responseDecodable$2.invokeSuspend(NotificareRequest.kt:92)
     	... 15 more

A workaround is downgrading AGP to version 7.4.2, changing gradle version doesn't seem to affect the issue.
I created a minimal GitHub project that reproduces the issue.

@hpinhal
Copy link
Contributor

hpinhal commented Jun 21, 2023

Hi @OvoMaS,

There is a known issue with Moshi where it fails to keep the JsonAdapter classes when the application is built with R8 enabled. This is now enabled by default with Gradle 8.0.

You can refer to this Moshi issue for a suggested workaround.
In short, you can temporarily add the following Proguard rule to your app.

-keep,allowobfuscation,allowshrinking class com.squareup.moshi.JsonAdapter

@OvoMaS
Copy link
Author

OvoMaS commented Jun 21, 2023

Hi @hpinhal,
Thanks for the quick reply and for the Moshi issue reference/fix!
May I suggest updating the troubleshoot section of the integration guide or even the GitHub README.md with this information? It would have saved me a few hours of debugging.

@OvoMaS OvoMaS closed this as completed Jun 21, 2023
@hpinhal
Copy link
Contributor

hpinhal commented Jun 22, 2023

Hi @OvoMaS,

We appreciate your suggestion.
The troubleshooting section was updated to reflect this issue.

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

2 participants