Skip to content

Coroutines exceptions not logged when android:sharedUserId is set #530

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
tsuharesu opened this issue Sep 5, 2018 · 3 comments
Closed
Assignees

Comments

@tsuharesu
Copy link

Right now I'm using launch blocks with Coroutines so when an UnhandledException occurs source, Android default handler can kick in and crash the app and log to Logcat. The latter is not happening.

After some research it happens that if I add android:sharedUserId="com.tsuharesu.shared" to my app Manifest.xml, Thread.getContextClassLoader() returns a dummy ClassLoader. Because of that, ServiceLoader fails to locate the resources and Thread.uncaughExceptionHandler is not called.

It looks like changing here https://github.com/Kotlin/kotlinx.coroutines/blob/master/core/kotlinx-coroutines-core/src/CoroutineExceptionHandlerImpl.kt#L13 to also use classLoader would fix it.

Sources:
https://stackoverflow.com/questions/13407006/android-class-loader-may-fail-for-processes-that-host-multiple-applications
ACRA/acra#656
ACRA/acra#657

@tsuharesu
Copy link
Author

As a workaround, right now I'm doing this in my application:

open class TsuApplication : Application() {
    override fun onCreate() {
        // This makes it log again
        Thread.currentThread().contextClassLoader = classLoader
        super.onCreate()
    }
}

@elizarov
Copy link
Contributor

elizarov commented Sep 6, 2018

Please check PR #531. Is this the solution your are proposing?

@tsuharesu
Copy link
Author

@elizarov yes! It seems to work now. Thank you.

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

2 participants