stacktrace-decoroutinator: Random crashes with java.lang.InternalError: Attempt to register dex file /data/user/0/../Anonymous-DexFile@1234.jar with multiple class loaders
Using stacktrace-decoroutinator in production will randomly crash the app at first attempt of using coroutines.
I have created a very small app that demonstrates it. See https://github.com/nordfalk/decoroutinator-app
After adding SD and a simple coroutine (https://github.com/nordfalk/decoroutinator-app/commit/613915a1737be032e66b7e1d80cf4ead07f98f86) the app crashes sometimes in pre-launch-report when uploading a signed app bundle to Google Play:
FATAL EXCEPTION: main
Process: dk.dinero.decoroutinatorapplication, PID: 20162
java.lang.InternalError: Attempt to register dex file /data/user/0/dk.dinero.decoroutinatorapplication/Anonymous-DexFile@188495102.jar with multiple class loaders
at dalvik.system.DexFile.defineClassNative(Native Method)
at dalvik.system.DexFile.defineClass(DexFile.java:298)
at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:291)
at dalvik.system.DexPathList$Element.findClass(DexPathList.java:772)
at dalvik.system.DexPathList.findClass(DexPathList.java:532)
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:245)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at dev.reformator.stacktracedecoroutinator.runtime.DecoroutinatorRuntime.load(runtime-android.kt:53)
at dev.reformator.stacktracedecoroutinator.runtime.DecoroutinatorRuntime.load$default(runtime-android.kt:26)
at dk.dinero.decoroutinatorapplication.MyApp.<init>(MyApp.kt:8)
at java.lang.Class.newInstance(Native Method)
at android.app.AppComponentFactory.instantiateApplication(AppComponentFactory.java:76)
at androidx.core.app.CoreComponentFactory.instantiateApplication(CoreComponentFactory.java:51)
at android.app.Instrumentation.newApplication(Instrumentation.java:1232)
at android.app.LoadedApk.makeApplicationInner(LoadedApk.java:1458)
at android.app.LoadedApk.makeApplicationInner(LoadedApk.java:1395)
Additionally, in our production app (private source) Ive:
- tried to strip all libraries, so that only SD remains.
- analized the APK and removed all providers, services and receivers (tools:node=“remove”)
- analized the bytecode for the initializer of the Application object and verified that DecoroutinatorRuntime.load() is absolutely the very first thing happening.
- moved DecoroutinatorRuntime.load() to the class initializer of the Application object
- verified that the bytecode for androidx.core.app.CoreComponentFactory has no influence - its instantiateApplication calls android.app.AppComponentFactory as the first thing, and so does the constructur
- verified that the PID of the process is changing every time (so, no process reuse)
Ive tried during more than a month to get this to work without random crashes at startup. I cant find out why it happens but I must have verified on 2 competely different codebases that it happens.
This issue is related to https://github.com/Anamorphosee/stacktrace-decoroutinator/issues/29 .
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 25 (13 by maintainers)
Commits related to this issue
- Use gradle plugin, as requested on https://github.com/Anamorphosee/stacktrace-decoroutinator/issues/30#issuecomment-2263649370 — committed to nordfalk/decoroutinator-app by nordfalk 2 years ago
They seems to have fixed the crashing! 🥳 I’ll roll out to a few hundred beta users and see what’ll happen.
some fixes were released in 2.4.5
@nordfalk version 2.4.4 was released. And since it ability to generate frames in runtime switching on by config:
@nordfalk There’s an unknown frame in your last trace (
dev.reformator.stacktracedecoroutinator.common.internal.UnknownKt.unknown(unknown.kt:20)). It appears when Decoroutinator cannot find a transformed class for a frame. Could you please add config below to yourbuild.gradle.ktsfile:to allow Decoroutinator to generates frames at runtime and check if there are unknown frames any more?
Hi, I just wanted to say that Ive found a way to make it work!
I had:
This worked in debug builds, but it didnt work in production builds - I didnt get good stack traces. Invoking
DecoroutinatorCommonApi.getStatus { it() }crashed with:After I added
-keep class dev.reformator.stacktracedecoroutinator.** { *; }to proguard-rules.pro it gave the output:DecoroutinatorStatus(successful=false, description=class [kotlin.coroutines.jvm.internal.BaseContinuationImpl] from Kotlin stdlib is not transformed)BUT
When I change to
then it works! 🥳 🥳 🥳
Sorry. My bad. Didn’t change version in one place. Please try version 2.4.1
Cool! I tried and in my test project I can use https://s01.oss.sonatype.org/content/repositories/snapshots/ but for some reason I fail to do it in my real project.
I have
but when I edit in app/gradle.build to add stacktracedecoroutinator
I get this error:
But it seems that your non-snapshot build works fine - this builds: