简体   繁体   中英

Android/Kotlin Crash on Start 4.1.2 - ExceptionInInitializerError

I'm using Kotlin within my app; however, when testing on lower API devices, it crashes on start.

Even attaching a debugger to the onCreate for the Splash Activity , it still crashes before any breakpoint.

I was able to get a callstack once, but I can't get any other callstacks.

Caused by: java.lang.NoClassDefFoundError: kotlin.jvm.internal.Intrinsics

╔════════════════════════════════════════════════════════════════════════════════════════
║ Thread: main
╟────────────────────────────────────���───────────────────────────────────────────────────
║ AppCompatDelegateImplBase$1.uncaughtException  (AppCompatDelegateImplBase.java:66)
║    App$1.uncaughtException  (App.java:59)
╟────────────────────────────────────────────────────────────────────────────────────────
║ java.lang.ExceptionInInitializerError
║   at com.my_company.app.ui.shared.BaseActivity.onStart(BaseActivity.kt:164)
║   at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1163)
║   at android.app.Activity.performStart(Activity.java:5018)
║   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2032)
║   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
║   at android.app.ActivityThread.access$600(ActivityThread.java:130)
║   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
║   at android.os.Handler.dispatchMessage(Handler.java:99)
║   at android.os.Looper.loop(Looper.java:137)
║   at android.app.ActivityThread.main(ActivityThread.java:4745)
║   at java.lang.reflect.Method.invokeNative(Native Method)
║   at java.lang.reflect.Method.invoke(Method.java:511)
║   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
║   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
║   at dalvik.system.NativeStart.main(Native Method)
║ Caused by: java.lang.NoClassDefFoundError: kotlin.jvm.internal.Intrinsics
║   at com.my_company.app.notification.NotificationType.<init>(NotificationType.kt)
║   at com.my_company.app.notification.NotificationType.<clinit>(NotificationType.kt:10)
║   ... 15 more
╚════════════════════════════════════════════════════════════════════════════════════════

Which points at: val intentFilter = IntentFilter(NotificationType.INVITE_RECEIVED)

which is an extension function that allows me pass my NotificationType enum into the IntentFilter.

enum class NotificationType(private val str: String) {

    // Orders
    ORDER_HOST_PAID("ORDER_HOST_PAID"),
    ...
}

I don't know what would cause this issue, as I use Kotlin in another app without this issue. Could it a gradle issue?

I'm using ext.kotlin_version = '1.2.0-beta-88'

It was because while I had multiDexEnabled true , I was not extending MultiDexApplication . That is only required if you're supporting API 20 or lower.

Adding the library to your dependencies.

android {
    defaultConfig {
        ...
        minSdkVersion 15 
        targetSdkVersion 26
        multiDexEnabled true
    }
    ...
}

dependencies {
  compile 'com.android.support:multidex:1.0.1'
}

And extending MultiDexApplication :

public class MyApplication extends MultiDexApplication

Answer: https://stackoverflow.com/a/39831657/3106174

I had the same error and I solved it with MultiDex, like described on this link : https://developer.android.com/studio/build/multidex.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM