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

Crash after R8/Proguard #24

Closed
Nojipiz opened this issue Aug 31, 2023 · 10 comments
Closed

Crash after R8/Proguard #24

Nojipiz opened this issue Aug 31, 2023 · 10 comments

Comments

@Nojipiz
Copy link

Nojipiz commented Aug 31, 2023

Please complete the following information:

  • Library Version: 1.0.6
  • Affected Device(s) All

Describe the Bug:

After minify the code with R8, can't use the library anymore, and throw an exception:

java.lang.IllegalArgumentException: Unable to create call adapter for retrofit2.Call<arrow.core.Either>

I have used the proguard rules described in Retrofit2 repository:

-keepattributes Signature, InnerClasses, EnclosingMethod, Exceptions, *Annotation*, AnnotationDefault, RuntimeVisibleAnnotations, RuntimeVisibleParameterAnnotations, InnerClasses, Annotation
-keepclassmembers,allowshrinking,allowobfuscation interface * {
    @retrofit2.http.* <methods>;
}
-dontwarn javax.annotation.**
-dontwarn kotlin.Unit
-dontnote retrofit2.Platform
-dontwarn retrofit2.KotlinExtensions
-dontwarn retrofit2.KotlinExtensions$*

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

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

-if interface * { @retrofit2.http.* public *** *(...); }
-keep,allowoptimization,allowshrinking,allowobfuscation class <3>

-keep,allowobfuscation,allowshrinking class retrofit2.Response
-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation
-keep,allowobfuscation,allowshrinking interface retrofit2.Call

According to the ArrowKt repository, it doesn't need extra rules in the proguard file.
Any idea of why this happen?

Expected Behavior:

It should work normally.

@skydoves
Copy link
Owner

Hey @Nojipiz, this is a known issue from OkHttp. This issue will be fixed in the next release. Thanks for creating this issue!

@skydoves
Copy link
Owner

skydoves commented Sep 1, 2023

Hey @Nojipiz, 1.0.7 stable has been released. Thanks for the issue!

@skydoves skydoves closed this as completed Sep 1, 2023
@nvkleban
Copy link

@skydoves Crash still happens in latest version, can you add please consumer proguard rules with

-keep,allowobfuscation,allowshrinking class arrow.core.Either

Source

@PavlosTze
Copy link

I agree with @nvkleban , the library keeps crashing. Can you please fix it @skydoves ?

@skydoves
Copy link
Owner

Hey @PavlosTze do you also face the issue from the retrofit-adapter-arrow library?

@skydoves
Copy link
Owner

@nvkleban 1.0.12 has been released and it contains the proguard rules itself.

@PavlosTze
Copy link

PavlosTze commented Aug 14, 2024

@skydoves Yes, I'm using the EitherCallAdapterFactory, and I'm having constant crashes on the "Release" version (where Proguard is used - Debug version works OK).

As soon as I added the following line in Proguard the issue has been fixed:
-keep,allowobfuscation,allowshrinking class arrow.core.Either

I was getting a bit different error, although the cause (Proguard) was the same:

Caused by java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType
at com.skydoves.retrofit.adapters.arrow.EitherCallAdapterFactory.checkLeftIsThrowable(EitherCallAdapterFactory.kt:91)
at com.skydoves.retrofit.adapters.arrow.EitherCallAdapterFactory.get(EitherCallAdapterFactory.kt:58)

@HeyPouya
Copy link

@skydoves Hi there
I was getting the same error for the Result adapter in the release build.
Adding this line fixed it for me:

-keep,allowobfuscation,allowshrinking class kotlin.Result

I'm using latest version of both retrofit and the adapter.

Here is the stack trace for your refrence:

java.lang.IllegalArgumentException: Unable to create call adapter for retrofit2.Call<kotlin.Result> for method PhotosApiServices.getPhotos-gIAlu-s at retrofit2.Utils.methodError(Utils.java:56) at retrofit2.HttpServiceMethod.createCallAdapter(HttpServiceMethod.java:129) at retrofit2.HttpServiceMethod.parseAnnotations(HttpServiceMethod.java:78) at retrofit2.ServiceMethod.parseAnnotations(ServiceMethod.java:39) at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:235) at retrofit2.Retrofit$1.invoke(Retrofit.java:177) at java.lang.reflect.Proxy.invoke(Proxy.java:1006) at $Proxy5.getPhotos-gIAlu-s(Unknown Source) at com.akorayan.photos.data.datasourse.PhotosDataSourceImpl.getPhotos(PhotosDataSourceImpl.kt:46) at com.akorayan.photos.data.repositoryimpl.PhotosRepositoryImpl$getPhotos$2.invokeSuspend(PhotosRepositoryImpl.kt:21) at com.akorayan.photos.data.repositoryimpl.PhotosRepositoryImpl$getPhotos$2.invoke(PhotosRepositoryImpl.kt:0) at com.akorayan.photos.data.repositoryimpl.PhotosRepositoryImpl$getPhotos$2.invoke(PhotosRepositoryImpl.kt:0) at kotlinx.coroutines.flow.SafeFlow.collectSafely(Builders.kt:57) at kotlinx.coroutines.flow.AbstractFlow.collect(Flow.kt:226) at kotlinx.coroutines.flow.internal.ChannelFlowOperatorImpl.flowCollect(ChannelFlow.kt:191) at kotlinx.coroutines.flow.internal.ChannelFlowOperator.collectTo$suspendImpl(ChannelFlow.kt:153) at kotlinx.coroutines.flow.internal.ChannelFlowOperator.collectTo(ChannelFlow.kt:0) at kotlinx.coroutines.flow.internal.ChannelFlow$collectToFun$1.invokeSuspend(ChannelFlow.kt:56) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104) at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:111) at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:99) at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:811) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:715) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:702) Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@967a7fa, Dispatchers.Main.immediate] Caused by: java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType at com.skydoves.retrofit.adapters.result.ResultCallAdapterFactory.get(ResultCallAdapterFactory.kt:58) at retrofit2.Retrofit.nextCallAdapter(Retrofit.java:309) at retrofit2.Retrofit.callAdapter(Retrofit.java:293) at retrofit2.HttpServiceMethod.createCallAdapter(HttpServiceMethod.java:127)

@MahdiPorkar-github
Copy link

I got the same error mentioned here by @HeyPouya
#24 (comment)

@rezazavvareh1993
Copy link

Please fix this bug

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

7 participants