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

Support R8 FullMode #1663

Open
G00fY2 opened this issue Apr 20, 2023 · 7 comments
Open

Support R8 FullMode #1663

G00fY2 opened this issue Apr 20, 2023 · 7 comments
Labels

Comments

@G00fY2
Copy link

G00fY2 commented Apr 20, 2023

Currently Moshi expects JsonAdapters to have the ParameterizedType. But the R8 fullMode (which is enabled by default since AGP8) strips signatures from non-kept items. Therefore the check in parametersAreJsonAdapters (also in the Kotlin implementation) fails because of this assumption and you run into a IllegalArgumentException at runtime.

I was able to fix this by adding the following proguard rule:
-keep,allowobfuscation,allowshrinking class com.squareup.moshi.JsonAdapter

I would expect this rule as part of the META-INF/proguard/moshi.pro

@G00fY2 G00fY2 added the bug label Apr 20, 2023
@ZacSweers
Copy link
Collaborator

Wanna send a PR? I'd want to see a full description of the implications of that rule and its attributes, but open to it!

@G00fY2
Copy link
Author

G00fY2 commented Apr 20, 2023

Currently I just copy pasta this rule from other Android library projects, e.g. this PR which also contains a nice explanation: square/retrofit#3579

I think this is also true for Moshi. But I am not really an expert on this topic.

@ZacSweers
Copy link
Collaborator

Well, PR welcome but would need an explanation of the side effects. We're unlikely to accept a PR with broad proguard/R8 implications without that kind of detail.

@DarkAbhi
Copy link

DarkAbhi commented Apr 27, 2023

Is this error due to moshi?

java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType
at retrofit2.HttpServiceMethod.parseAnnotations(HttpServiceMethod.java:46)
at retrofit2.ServiceMethod.parseAnnotations(ServiceMethod.java:39)
at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:202)
at retrofit2.Retrofit$1.invoke(Retrofit.java:160)
at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
at $Proxy11.checkIfEmailExists(Unknown Source)
at com.iku.data.network.service.IkuApiService$DefaultImpls.checkIfEmailExists$default(IkuApiService.kt:123)
at com.iku.auth.data.network.repository.AuthRepositoryImpl$checkEmail$2.invokeSuspend(AuthRepositoryImpl.kt:24)
at com.iku.auth.data.network.repository.AuthRepositoryImpl$checkEmail$2.invoke(AuthRepositoryImpl.kt:0)
at com.iku.auth.data.network.repository.AuthRepositoryImpl$checkEmail$2.invoke(AuthRepositoryImpl.kt:0)
at com.iku.data.network.helper.NetworkHelperKt$safeApiCall$2.invokeSuspend(NetworkHelper.kt:27)
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)

I have retrofit and moshi, just upraded to AS flamingo with AGP 8 and Java 17. This error causes retrofit calls to not happen.
Here's more details on stackoverflow - https://stackoverflow.com/questions/76118721/r8-full-mode-throws-class-cast-exception-agp-8-0

@G00fY2
Copy link
Author

G00fY2 commented Apr 27, 2023

@DarkAbhi Nope, your stacktrace seems not to be related to Moshi, since it would run into this error: https://github.com/square/moshi/blob/1.14.0/moshi/src/main/java/com/squareup/moshi/AdapterMethodsFactory.java#L226

@DarkAbhi
Copy link

@DarkAbhi Nope, your stacktrace seems not to be related to Moshi, since it would run into this error: https://github.com/square/moshi/blob/1.14.0/moshi/src/main/java/com/squareup/moshi/AdapterMethodsFactory.java#L226

Right, thanks. I'm going to be running around a lot figuring this out..

@DarkAbhi
Copy link

@G00fY2 @ZacSweers Would you have any idea about this issue?
This is the only live project I have with Moshi, my other projects with GSON work fine so far after AGP 8 and Flamingo update.
Thanks!

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

No branches or pull requests

3 participants