Skip to content

Provider kotlinx.coroutines.experimental.android.AndroidExceptionPreHandler not found #214

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

Closed
GeoffreyMetais opened this issue Feb 1, 2018 · 9 comments
Labels

Comments

@GeoffreyMetais
Copy link

We recently pushed VLC on beta, with some Kotlin code.
And we see some users reporting this ClassNotFoundException
Project configuration is:
Kotlin version 1.2.21
Kotlinx version 0.21.2

Identified devices are:
Acer GT-810 (rolex) Android 5.1
OnePlus One (A0001) Android 4.3
Xiaomi Redmi Note 4 (mido) Android 7.0

VLC gradle build files are here and here

Concerned exception handler here.

kotlinx.coroutines.experimental.DispatchException: Unexpected exception running DispatchedContinuation[UI, org.videolan.vlc.gui.DiffUtilAdapter$internalUpdate$2@c13506a]
	at kotlinx.coroutines.experimental.DispatchedTask$DefaultImpls.run(Dispatched.kt:165)
	at kotlinx.coroutines.experimental.DispatchedContinuation.run(Dispatched.kt:25)
	at android.os.Handler.handleCallback(Handler.java:754)
	at android.os.Handler.dispatchMessage(Handler.java:95)
	at android.os.Looper.loop(Looper.java:163)
	at android.app.ActivityThread.main(ActivityThread.java:6237)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:877)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
	at Android.MODEL(Redmi Note 4)
	at Android.VERSION(7.0)
	at Android.FINGERPRINT(xiaomi/mido/mido:7.0/NRD90M/V9.0.5.0.NCFMIEI:user/release-keys)
Caused by: java.util.ServiceConfigurationError: kotlinx.coroutines.experimental.CoroutineExceptionHandler: Provider kotlinx.coroutines.experimental.android.AndroidExceptionPreHandler not found
	at java.util.ServiceLoader.fail(ServiceLoader.java:225)
	at java.util.ServiceLoader.-wrap1(ServiceLoader.java)
	at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:366)
	at java.util.ServiceLoader$1.next(ServiceLoader.java:448)
	at kotlinx.coroutines.experimental.CoroutineExceptionHandlerKt.handleCoroutineException(CoroutineExceptionHandler.kt:98)
	at kotlinx.coroutines.experimental.StandaloneCoroutine.onCancellation(Builders.kt:185)
	at kotlinx.coroutines.experimental.JobSupport.completeUpdateState$kotlinx_coroutines_core(Job.kt:718)
	at kotlinx.coroutines.experimental.JobSupport.updateState$kotlinx_coroutines_core(Job.kt:659)
	at kotlinx.coroutines.experimental.JobSupport.makeCompletingInternal$4cfcfd05(Job.kt:1051)
	at kotlinx.coroutines.experimental.JobSupport.makeCompletingOnce$kotlinx_coroutines_core$4cfcfd16(Job.kt:1037)
	at kotlinx.coroutines.experimental.AbstractCoroutine.resumeWithException(AbstractCoroutine.kt:48)
	at kotlin.coroutines.experimental.jvm.internal.CoroutineImpl.resume(CoroutineImpl.kt:53)
	at kotlinx.coroutines.experimental.DispatchedTask$DefaultImpls.run(Dispatched.kt:161)
	at kotlinx.coroutines.experimental.DispatchedContinuation.run(Dispatched.kt:25)
	at android.os.Handler.handleCallback(Handler.java:754)
	at android.os.Handler.dispatchMessage(Handler.java:95)
	at android.os.Looper.loop(Looper.java:163)
	at android.app.ActivityThread.main(ActivityThread.java:6237)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:877)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.ClassNotFoundException: kotlinx.coroutines.experimental.android.AndroidExceptionPreHandler
	at java.lang.Class.classForName(Native Method)
	at java.lang.Class.forName(Class.java:400)
	at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:364)
	... 18 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "kotlinx.coroutines.experimental.android.AndroidExceptionPreHandler" on path: DexPathList[[zip file "/data/app/org.videolan.vlc-2/base.apk"],nativeLibraryDirectories=[/data/app/org.videolan.vlc-2/lib/arm64, /data/app/org.videolan.vlc-2/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]
	at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
	... 21 more
@elizarov elizarov added the bug label Feb 1, 2018
@elizarov
Copy link
Contributor

elizarov commented Feb 1, 2018

That seems to a ProGuard issue. kotlinx.coroutines.experimental.android.AndroidExceptionPreHandler seems to have been removed by ProGuard, even though it is references from META-INF/services/kotlinx.coroutines.experimental.CoroutineExceptionHandler and should have been kept. Most likely, it needs to be explicitly configured to "keep". I'm extremely surprised it is not kept by default. It is either ProGuard bug or some project-specific ProGuard configuration that is causing it. Can you share your ProGuard configuration, please?

@JakeWharton
Copy link
Contributor

You explicitly have to add

# The Android pre-handler for exceptions is loaded reflectively (via ServiceLoader).
-keep class kotlinx.coroutines.experimental.android.AndroidExceptionPreHandler { *; }

@GeoffreyMetais
Copy link
Author

GeoffreyMetais commented Feb 1, 2018

Thank you!

But it would be systematic if it was the case no?
Here, it only happens on a very few devices with the same app build.

@GeoffreyMetais
Copy link
Author

@elizarov
Copy link
Contributor

elizarov commented Feb 1, 2018

The reason it is not systematic is that it happens only when some other uncaught exception happens. The app is about the crash, but the code that is supposed to handle that cannot handle the exception, because it cannot find kotlinx.coroutines.experimental.android.AndroidExceptionPreHandler class that should be there. I'm having hard time reproducing it. I cannot figure out how it can be happening.

@elizarov
Copy link
Contributor

elizarov commented Feb 1, 2018

I've assembled vlc-android release on my machine and looked into resulting apk and into the dex file inside. Indeed, kotlinx.coroutines.experimental.android.AndroidExceptionPreHandler is not there. I turns out I can reproduce it with a simple project. I see when minifyEnabled true then this class gets removed from the .dex. I still cannot reproduce it under emulator, since I cannot figure out how to deploy my "release" apk there. It seems to be deploying "debug" apk under emulator which does not experience this problem.

@GeoffreyMetais
Copy link
Author

Yes, proguard only applies on release builds.

adb install -r app_release.apk ?

@Karthika-Kishore
Copy link

Karthika-Kishore commented Feb 23, 2024

Our team is getting recently having this crash.

Caused by java.lang.ArrayStoreException
kotlinx.coroutines.android.AndroidExceptionPreHandler cannot be stored in an array of type qh.b0[]

Adding below lines also doesn't helped.

The Android pre-handler for exceptions is loaded reflectively (via ServiceLoader).

-keep class kotlinx.coroutines.experimental.android.AndroidExceptionPreHandler { *; }

Please let me know is there a way to fix this.

@dkhalanskyjb
Copy link
Collaborator

@Karthika-Kishore, please contact Android maintainers or the manufacturer of the device. This looks like a bug in modification facilities.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants