Crash ExoPlayer.Builder in android version 5 and 6 (android api 21 and 23)

Viewed 370

When I upgrade exoplayer to version 2.16.0, it crashes when I run the line below the code:

exoPlayer = ExoPlayer.Builder(this).build()

I tested on higher Androids version like 10 and 11 (android api 29 and 30) and there is no problem, but in Android version 5 and 6 it crashes (android api 21 and 23) Previously, in version 2.11.8, which I used, it ran without any problems in all versions of Android, but since I updated it to version 2.16.0, I have seen this problem in Android version 5 and 6.

What should I do to solve this problem?

My error log:

java.lang.NoClassDefFoundError: com.google.android.exoplayer2.ExoPlayer$Builder$$ExternalSyntheticLambda0
     at com.google.android.exoplayer2.ExoPlayer$Builder.<init>(ExoPlayer.java:440)
     at com.myapp.Activity.VideoActivity_Online.onCreate(VideoActivity_Online.kt:58)
     at android.app.Activity.performCreate(Activity.java:6237)
     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
     at android.app.ActivityThread.-wrap11(ActivityThread.java)
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
     at android.os.Handler.dispatchMessage(Handler.java:102)
     at android.os.Looper.loop(Looper.java:148)
     at android.app.ActivityThread.main(ActivityThread.java:5417)
     at java.lang.reflect.Method.invoke(Native Method)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
2 Answers

I use com.squareup.moshi:moshi-kotlin-codegen:1.12.0 in my project and face same issue with Exoplayer. Probably moshi codegen breaks desugaring mechanics (Exoplayer code contains java 8 lambdas). If you use moshi too, try downgrade or upgrade moshi version. Also check other code generation tools used by your project.

Upd: I found that in one of project modules i use implementation com.squareup.moshi:moshi-kotlin-codegen:1.12.0 instead kapt com.squareup.moshi:moshi-kotlin-codegen:1.12.0. After replacing from implementation to kapt all works as expected.

In my case, the error was caused by this dependency: `org.jetbrains.kotlinx:kotlinx-coroutines-guava` (don't ask me why, it doesn't make any sense to be honest), which I used to await a `ListenableFuture` within a `CoroutineScope`.

I solved by removing the dependency.

EDIT: The problem is there's a library that uses Java 8 language features. You need to enable desugaring.

Related