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

After upgrading to AGP 8, started getting invalid @FromJson method signature error #3934

Closed
aaleksievcmc opened this issue Aug 3, 2023 · 2 comments

Comments

@aaleksievcmc
Copy link

After upgrade to AGP 8, moshi started throwing throwing

java.lang.IllegalArgumentException: Unexpected signature for public final com.cmcmarkets.mobile.android.invest.data.api.model.OrderStatusResponseDTO com.cmcmarkets.mobile.android.invest.data.api.adapters.OrderStatusResponseDTOAdapter.fromJson(com.squareup.moshi.JsonReader,com.squareup.moshi.JsonAdapter,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>;

I've added additional proguard rules but that didn't help

# R8 full mode strips generic signatures from return types if not kept.
-if interface * { @retrofit2.http.* public *** *(...); }
-keep,allowoptimization,allowshrinking,allowobfuscation class <3>

-keep class com.cmcmarkets.mobile.android.invest.data.api.model.OrderStatusResponseDTO
-keepclassmembers class com.cmcmarkets.mobile.android.invest.data.api.model.OrderStatusResponseDTO {
  *;
}

OrderStatusResponseDTO is sealed class

@HGyllensvard
Copy link

I just ran into this issue as well upgrading from AGP 7.x to 8.1

I would recommend looking at the Moshi library, the proguard suggestion here unblocked me.

@JakeWharton
Copy link
Collaborator

Each version of AGP comes with a newer version of R8 that can add optimizations or enable new functionality. In AGP 8 I believe R8's full mode became the default. Thus, you may need to add new shrinker rules to ensure functions which are accessed via reflection (as Moshi does) are retained.

If you aren't able to figure it out based on the other reply's link, I would suggest asking on Moshi's discussions or StackOverflow using the 'moshi' tag.

Retrofit is the one asking Moshi to deserialize the body, but otherwise Moshi is a black box to Retrofit. We ask it to deserialize the bytes to a type and then wait for it to return. What Moshi does internally is entirely a Moshi thing. Or, put another way, if you manually asked Moshi to deserialize a string or bytes into that same type directly you would experience the same problem. Thus, there's really nothing that Retrofit can do here aside from try to point you to the right place to get help with Moshi.

@JakeWharton JakeWharton closed this as not planned Won't fix, can't repro, duplicate, stale Aug 15, 2023
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