2

I am facing an issue with my app: If I deactivate within Android Studio Instant Run, my app crashes upon startup with the stacktrace:

12-29 13:36:37.876 4549-4549/com.mycoolapp.debug E/AndroidRuntime: FATAL EXCEPTION: main
                                                                              Process: com.mycoolapp.debug, PID: 4549
                                                                              java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.mycoolapp.debug/com.myapp.SplashScreenActivity}: java.lang.ClassNotFoundException: Didn't find class "com.myapp.SplashScreenActivity" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/data/app/com.mycoolapp.debug-2/base.apk"],nativeLibraryDirectories=[/data/app/com.mycoolapp.debug-2/lib/arm, /vendor/lib, /system/lib]]
                                                                                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2216)
                                                                                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2365)
                                                                                  at android.app.ActivityThread.access$800(ActivityThread.java:148)
                                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
                                                                                  at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                  at android.os.Looper.loop(Looper.java:135)
                                                                                  at android.app.ActivityThread.main(ActivityThread.java:5272)
                                                                                  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:909)
                                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:704)
                                                                               Caused by: java.lang.ClassNotFoundException: Didn't find class "com.myapp.SplashScreenActivity" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/data/app/com.mycoolapp.debug-2/base.apk"],nativeLibraryDirectories=[/data/app/com.mycoolapp.debug-2/lib/arm, /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.newActivity(Instrumentation.java:1065)
                                                                                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2206)
                                                                                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2365) 
                                                                                  at android.app.ActivityThread.access$800(ActivityThread.java:148) 
                                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283) 
                                                                                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                  at android.os.Looper.loop(Looper.java:135) 
                                                                                  at android.app.ActivityThread.main(ActivityThread.java:5272) 
                                                                                  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:909) 
                                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:704) 
                                                                                Suppressed: java.lang.NoClassDefFoundError: com.myapp.SplashScreenActivity
                                                                                  at dalvik.system.DexFile.defineClassNative(Native Method)
                                                                                  at dalvik.system.DexFile.defineClass(DexFile.java:226)
                                                                                  at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:219)
                                                                                  at dalvik.system.DexPathList.findClass(DexPathList.java:321)
                                                                                  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
                                                                                        ... 14 more
                                                                                Suppressed: java.lang.ClassNotFoundException: com.myapp.SplashScreenActivity
                                                                                  at java.lang.Class.classForName(Native Method)
                                                                                  at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
                                                                                  at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
                                                                                  at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
                                                                                        ... 13 more
                                                                               Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

As far as I have researched this belongs to multidex: https://developer.android.com/studio/build/multidex.html

Even if I add the multiDexEnabled property to my gradle config the app crashes. Only if I enable InstantRun (which enables multidex in background), the app runs... If I create an apk the installation works, but the app crashes on startup with the same error.

Since I have as minSDK API Level 21, there should be no other change except of the multiDexEnabled property necessary, right?

3
  • check your manifest package name...SplashScreenActivity whether it is defined properly Commented Dec 29, 2016 at 15:35
  • Your Application class extends from MultiDexApplication? Commented Dec 29, 2016 at 15:47
  • Manifest is OK, I also tried to extend from MultiDexApplication without any success. The androids doc also says that this is only necessary if you have minSDK < 21. Commented Dec 29, 2016 at 16:57

4 Answers 4

2

So last but not least my answer: All my configuration for multidex was correct... I don't know why, but after a complete OS restart everything works fine now... :)

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you!! i updated the gradle wrapper and then i kept getting the same error, every time i ran the application the application subclass could not be found even though multidex was set up properly, after hours of trying to understand whats wrong and trying a million different things(even Invalidate Caches / Restart didn't work) i ran into your post, restarted my OS and then it just worked.
@Kostyantin2216 what OS? on computer or on smartphone?
@ElSajko Windows 7 computer, i posted a new answer as this answer was only a temporary fix for me.
1

Just create new phone on AVD and try to install app on that phone. Hope it will work.

1 Comment

This is a solution?
0

The accepted answer was only a temporary fix for me, after altering code and a few builds the error came back.

After alot of trial and error the real problem was the jdk location my project was using, instead of using the embedded jdk in android studio i was using an installed version from oracle. After going to File > Project Structure > SDK Location and checking Use embedded JDK the problem was fixed for good.

Comments

0

Check if your classpath

'com.android.tools.build:gradle:3.1.0-alpha05'

is up-to-date, had same problem and solved it with a full update.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.