-
Notifications
You must be signed in to change notification settings - Fork 7.3k
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
Comments
I think we have a problem which relates to yours: https://stackoverflow.com/questions/78518260/r8-shrinker-removes-retrofit-interfaces But instead of using our instance that we created using |
Debug mode works fine, but once released mode causes very stubborn java.lang. ClassCastException |
Add @keep annotation to the interface solved my problem |
我的问题得到了解决,方法是与服务端交互的JSON对象类不混淆,例如:
|
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:
retrofit/retrofit/src/main/resources/META-INF/proguard/retrofit2.pro
Line 31 in dfdad42
Then once you try to instantiate the stripped service class, you get a fairly nondescript
ClassCastException
from Retrofit. E.g.:Replacing the referenced rule with the following one fixes the issue for us:
(Source: here)
Note: I barely know how to proguard, so this definitely requires some scrutiny. Raising issue here for visibility.
The text was updated successfully, but these errors were encountered: