Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

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.

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

No branches or pull requests

2 participants