Just ran into a runtime crash after updating to 1....
# android
Just ran into a runtime crash after updating to 1.5.0 with an Android Emulator running on API 16:
Copy code
E/AndroidRuntime( 3715): Caused by: java.lang.NoClassDefFoundError: kotlin.collections.EmptyList
E/AndroidRuntime( 3715):        at kotlin.collections.CollectionsKt__CollectionsKt.emptyList(SourceFile:71)
E/AndroidRuntime( 3715):        at kotlin.collections.CollectionsKt.emptyList(SourceFile)
E/AndroidRuntime( 3715):        ... 16 more
However, this crash does not happen on newer versions of Android (API 29) or if we have
kotlinOptions.useOldBackend = true
, any idea what's the underlying cause in the new IR back-end that would cause it to crash on older versions of Android?
maybe you're just getting unlucky with multidex?
That might be the case, I am so ignorant on how the build tools prioritize what gets put into the main dex file. Would one configure multidex to keep all of Kotlin and Kotlinx in the main dex file?
This shouldn't happen for code that's accessed directly from your app code because the build tools recognize those code paths, but it can happen when the code paths are less visible such as when a library you use has complex dependencies. For example, if the code uses introspection or invocation of Java methods from native code, then those classes might not be recognized as required in the primary DEX file.
- https://developer.android.com/studio/build/multidex#keep ☝️ We are not doing anything tricky, so the build tools should be able to figure it out. Is the new IR back-end doing something tricky that might be tripping it up?
it could just be random other changes that make multidex behave differently, not this in particular
I am pretty sure it has to do with the new IR back-end that is now default in 1.5. It's fairly reproducible on our end.
if you are relying on multidex, you can't use anything from non-main classes.dex before MultidexApplication has set up. do you have a custom Application and does it reference any other classes?
We do multidex and we do have a custom application class that references other classes directly.
We tried to repro in a test applications and we cannot replicate 😞
And it seems to be only happening on devices < 21, so in the compatibility case for multi-dexing
The plot thickens. We inspected the apk and found
in the main dex file
🤔 1
that's very strange. we did used to see some inexplicable behavior on devices from some manufacturers that patched their pre-21 framework with multidex in a broken way, but rarely anything very consistent…
in our case, we're happy to be API 24+ now 🙂