I encountered an issue with using Coroutines Stacktrace recovery on Android. I followed official documentation but seems like Im missing something.
I enabled debug mode with System.setProperty("kotlinx.coroutines.debug", "on");
in my project's Application
class onCreate
, but it does not seem to work for me no matter what I do.
For example this code:
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
runBlocking {
callerFunction1()
}
}
fun callerFunction1() {
CoroutineScope(Dispatchers.Main + CoroutineName("Caller1")).launch {
intermediateFunction1()
}
}
suspend fun intermediateFunction1() {
delay(100)
intermediateFunction3()
}
suspend fun intermediateFunction2() {
delay(100)
crashFunction()
}
will trim the stack trace only to crashFunction
call without any callers info.
Is there a chance to obtain a trace in a way: crashFunction
-> intermediateFunction2
-> intermediateFunction1
?
What I tried:
- Using Coroutine ExceptionHandler
- Using try-catch at the top level
- Using my CustomException which implements CopiableThrowable
- Using other types of exception like IllegalStateException
Environment
- Android
- Standard debug build - no Proguard or R8
- kotlin 2.0.0
- coroutinesVersion 1.8.1