0

I'm currently developing an AndroidTV application using Jetpack Compose, Retrofit, and Coroutines. To test the performance issues in my project, I need to enable R8 mode. However, when I do so, I encounter the following error:

Fatal Exception: java.lang.ClassCastException:
   at com.xx.xx.domain.home.usecase.XxxXUseCase$invoke$2.invokeSuspend(XxxXUseCase.kt:24)
   at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
   at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
   at android.os.Handler.handleCallback(Handler.java:942)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at android.os.Looper.loopOnce(Looper.java:201)
   at android.os.Looper.loop(Looper.java:288)
   at android.app.ActivityThread.main(ActivityThread.java:7898)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

or (with obfuscation):

Fatal Exception: java.lang.ClassCastException:
   at a.d.s(:5)
   at u6.a.h(SourceFile:81)
   at ic.a.t(SourceFile:9)
   at yc.e0.run(SourceFile:116)
   at android.os.Handler.handleCallback(Handler.java:942)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at android.os.Looper.loopOnce(Looper.java:201)
   at android.os.Looper.loop(Looper.java:288)
   at android.app.ActivityThread.main(ActivityThread.java:7898)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

Here's my configuration:

  • Jetpack Compose version: "1.6.0-SNAPSHOT" (required for tv apis)
  • Kotlin(Coroutines) version: "1.8.22" (I need to use versions below version 1.9.0 for Hilt For Hilt)
  • Android Studio version: "Android Studio Giraffe | 2022.3.1"
  • Gradle version: 'com.android.tools.build:gradle:8.1.0'

My "build.gradle" file

release {
 minifyEnabled true

 firebaseCrashlytics {
  mappingFileUploadEnabled true
 }

 proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 
  'proguard-rules.pro'

 signingConfig signingConfigs.debug
}

My "proguard-rules.pro" file:

-keepattributes Signature


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

# Kotlin Coroutines
-dontwarn kotlin.**
-dontwarn kotlinx.atomicfu.** 
-keepnames class kotlinx.coroutines.internal.MainDispatcherFactory {}
-keepnames class kotlinx.coroutines.CoroutineExceptionHandler {}
-keepnames class kotlin.ResultKt {}
-keepclassmembernames class kotlinx.** {
    volatile <fields>;
}

I've tried to look into the documentation and search online for this specific error but couldn't find any relevant solutions. After some research, I also added the following code, but it didn't work:

-keepnames class kotlin.ResultKt {}

Has anyone faced this issue before, and how can I resolve it?

Additionally, it's worth mentioning that the application does not crash in debug mode or when "minifyEnabled" is set to false.

Any help would be appreciated. Thank you!

Kerim Bora
  • 63
  • 7
  • Usually, a `ClassCastException` shows you what cast failed specifically. Is there more to your stack trace? Also, what is the line that is failing (`XxxXUseCase.kt:24`)? – CommonsWare Aug 06 '23 at 16:11
  • 1
    Here is my there check it please https://stackoverflow.com/questions/76073318/upgrading-gradle-from-7-4-2-to-gradle-8-0-0-gives-error-on-release-app-java-la – Chirag Thummar Aug 07 '23 at 06:48

1 Answers1

0

this solved it:

in gradle.properties:

android.enableR8.fullMode=false

Kerim Bora
  • 63
  • 7
  • If turning off "full mode" works, it might be https://github.com/square/retrofit/issues/3005. As far as I can see Retrofit has not been released since this was fixed, so you could try out the rules mentioned here https://r8.googlesource.com/r8/+/refs/heads/main/compatibility-faq.md#retrofit with full mode turned on. – sgjesse Aug 14 '23 at 11:04