-
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
[Android] [R8] IllegalArgumentException
thrown when calling a service operation with unused return type
#4011
Comments
Check #3751 (comment). |
Thanks for the pointer @Goooler! I believe the issue still happens with those rules added. The sample project to repro the problem shared in the issue has the rules that follow:
|
This is #3588. There is no workaround via rules. You must explicitly keep the concrete types. I'll move the annotation processor once I'm off of pat leave. |
By the way, thanks for the repro! Too few issues have them leading me to guess at the problem, cause, and fix. My responses are terse because I'm on mobile! |
Steps to reproduce:
Android app project with code to repro the issue: https://github.com/vjgarciag96/retrofit-unused-return-bug-repro
Retrofit version is 2.9.0, but I imagine it can be reproduced in earlier version too.
Cause
I believe the problem is caused by a combination of R8, retrofit, and
Json
'sConverterFactory
in this example:ResponseBody
type is unused, and so it removes the class and replaces its usages with theObject
type.ExampleApiService.getOperation
, it delegates toJson
sConverterFactory
, which will provide the appropriate deserializer.Json
sConverterFactory
finds that the type it needs to provide a deserializer for isObject
(orAny
in the Kotlin world) and fails because it does not know how to do that.Solution
A simple solution would be to remove the unused
ResponseBody
class, and replace its usage withUnit
. This works fine and fixes the issue, although I'm not sure whether you could run into the same problem when building a release build if you only use the result in debug builds.Issue?
I'm still not sure this is an issue
retrofit
should try to prevent, but it feels like it is something that apps could run into inadvertently so perhaps it could be a good idea to ship consumer proguard rules in the library that would prevent an scenario like that from happening? I'm keen to hear thoughts and opinions about this, thanks!The text was updated successfully, but these errors were encountered: