We have multiple interfaces which inherit from another
interface ApiInterface : AuthMobileApiInterface, DashboardApiInterface {
...
@GET("rest/user/context")
fun getUserContext(): Call<UserContext>
...
}
AuthMobileApiInterface
and DashboardApiInterface
are containing methods with retrofit annotations as well.
We also have a class DemoApi
which implements ApiInterface
but as the name suggests is only used while in demo mode.
While upgrading to Gradle 8.4 and AGP 8.3.2 we experienced a ClassCastException
->
retrofit2.DefaultCallAdapterFactory$ExecutorCallbackCall cannot be cast to DemoApi.getUserContext.Call
.
The cast exception itself makes sense because ExecutorCallbackCall
implements Call
but our DemoApi
only provides a Call
implementation.
The thing that makes no sense is that the application used our DemoApi
everywhere where we used the ApiInterface
instead of the service instance created via retrofit.create()
.
This happened with minification enabled only.
After playing around with ProGuard rules we found out that annotating all involved interfaces with @Keep
resolved the issue.
I want to understand R8 and retrofit.
My questions are:
- Is this a retrofit bug?
- Did we missed something of the retrofit documentation?
- Is annotating all interfaces with
@Keep
a valid solution or did we messed up something?
Any guidance to understand the situation is welcome.
Facts
- Gradle 8.4
- AGP 8.3.2
- retrofit 2.11.0
android.enableR8.fullMode=false
References
- Upgrading Gradle from 7.4.2 to Gradle 8.0.0 gives error on release app – java.lang.ClassCastException