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

ClassCastException thrown from unused Retrofit services with R8 #4134

Open
grandstaish opened this issue Apr 30, 2024 · 0 comments
Open

ClassCastException thrown from unused Retrofit services with R8 #4134

grandstaish opened this issue Apr 30, 2024 · 0 comments

Comments

@grandstaish
Copy link

grandstaish commented Apr 30, 2024

Bit of an edge case here—but if all of the functions in a Retrofit interface are unused, R8 will strip them. This causes the following Proguard rule to miss:

-if interface * { @retrofit2.http.* <methods>; }

Then once you try to instantiate the stripped service class, you get a fairly nondescript ClassCastException from Retrofit. E.g.:

Caused by: java.lang.ClassCastException
  at androidx.appcompat.app.ToolbarActionBar$$ExternalSyntheticThrowCCEIfNotNull0.m(:0)

Replacing the referenced rule with the following one fixes the issue for us:

-if interface *
-keepclasseswithmembers,allowobfuscation interface <1> {
  @retrofit2.http.* <methods>;
}

(Source: here)

Note: I barely know how to proguard, so this definitely requires some scrutiny. Raising issue here for visibility.

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

1 participant