IliaEremin
IliaEremin

Reputation: 3397

Unable to instantiate application java.lang.ClassNotFoundException. Didn't find class "Application" on path: DexPathList

After I run gradle clean and build and upload apk on device my app crash on start with following exception. I use Android Studio 1.3.1.

  java.lang.RuntimeException: Unable to instantiate application my.package.MyApplication: java.lang.ClassNotFoundException: Didn't find class "my.package.MyApp" on path: DexPathList[[zip file "/data/app/com.unated-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
        at android.app.LoadedApk.makeApplication(LoadedApk.java:569)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4589)
        at android.app.ActivityThread.access$1500(ActivityThread.java:149)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1385)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:211)
        at android.app.ActivityThread.main(ActivityThread.java:5317)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1016)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
 Caused by: java.lang.ClassNotFoundException: Didn't find class "com.unated.ProductionApp" on path: DexPathList[[zip file "/data/app/com.unated-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
        at android.app.Instrumentation.newApplication(Instrumentation.java:979)
 Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

I have 2 flavors: production and staging. And I have two different Application classes for each flavor. I read RuntimeException: Unable to instantiate application but killing app from recent list does not work. If I change flavor then some times app starts to work. And sometimes if I change flavor back it starts to work (but often not). I can not figure out how to make it work. Very annoying thing, please help!

Upvotes: 1

Views: 3943

Answers (1)

JohnWatsonDev
JohnWatsonDev

Reputation: 1237

Add below code segment in your build.gradle in app module.

dexOptions {
  preDexLibraries false
}

Upvotes: 2

Related Questions