8

I updated to Android Studio 2.1 from the stable channel. As soon as I did that I am getting ClassNotFoundException to my login class, which is declared in the manifest for long time. Prior to the update my app was compiling fine.

com.myapp E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.myapp, PID: 29605
    java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.myapp/com.myapp.Login}: java.lang.ClassNotFoundException: Didn't find class "com.myapp.Login" on path: DexPathList[[zip file "/data/app/com.myapp-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3023)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3294)
    at android.app.ActivityThread.access$1000(ActivityThread.java:210)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1704)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:145)
    at android.app.ActivityThread.main(ActivityThread.java:6938)
    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:1404)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
    Caused by: java.lang.ClassNotFoundException: Didn't find class "com.myapp.Login" on path: DexPathList[[zip file "/data/app/com.myapp-1/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.newActivity(Instrumentation.java:1094)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3013)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3294) 
    at android.app.ActivityThread.access$1000(ActivityThread.java:210) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1704) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:145) 
    at android.app.ActivityThread.main(ActivityThread.java:6938) 
    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:1404) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199) 
    Suppressed: java.lang.ClassNotFoundException: com.myapp.Login
    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

This is my gradle.build

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
    compileSdkVersion 'Google Inc.:Google APIs:23'
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.myapp"
        minSdkVersion 14
        targetSdkVersion 22
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
//    compile files('libs/smack-core-4.0.7.jar')
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.google.android.gms:play-services:7.8.0'
    compile 'com.google.maps.android:android-maps-utils:0.4+'
}

So far I have tried 1)Clean and rebuild project 2)Delete the build folder and rebuild project/restart Android Studio 3)Switch to canary channel as well as dev channel and update 4)Check and uncheck the offline mode in Settings Obviously this is a bug, but is there a solution to this? How can I reverse the recent updates? Any help is much appreciated.

Nongthonbam Tonthoi
  • 12,667
  • 7
  • 37
  • 64
The_Martian
  • 3,684
  • 5
  • 33
  • 61

8 Answers8

10

Try this:

Clear app cache

Clear app data

Uninstall app

Run/Debug again

Hope it works!

Nongthonbam Tonthoi
  • 12,667
  • 7
  • 37
  • 64
6

We are experiencing a similar error after updating to version 2.1 of Android Studio. A class added long ago is now not being found on application start. It's only happening with Android 5.1 and 5.1.1. Really weird crash!

The solution to this was enabling "Instant Run" solves the issue on Lollipop.

Andy
  • 49,085
  • 60
  • 166
  • 233
Ferran Pons
  • 81
  • 1
  • 4
  • In my case it was also "Instant Run" related, but I had to disable it to get it running again. After the first successful run, I enabled "Instant Run" again and it worked. – lbarbosa Oct 22 '17 at 08:52
  • @Ferran Pons: I have the same problem with Lollipop devices, turning Instant Run on worked for me, but I don't want to use Instant Run, anyway to disable it without problem? – Lê Thái Phúc Quang Nov 24 '17 at 04:26
  • @LêTháiPhúcQuang AFAIK the only option is to use a different device with a higher API. Sorry for replying so late. – Ferran Pons Jan 25 '18 at 14:36
  • @FerranPons hi there, it has been while since my last comment, i've just take a look and the problem has gone without Instant Run enabled. But I have no idea when did I turn off Instant Run. – Lê Thái Phúc Quang Jan 26 '18 at 07:21
2

I experienced this error and had looked at a number of SO threads, and various resources and also checked in to the android dev irc. The answers seem to follow a trend:

Gradle/Android Studio General:

Clean build, reset Android Studio caches, uninstall/reinstall android studio, leave Android Studio and come back to it in 2 hours, restart your computer.

Referencing the class

Is it correctly listed through the manifest? What about gradle configuration?

Loading Classes via IDE (though that seems mostly eclipse related)

Libraries do not get added to APK anymore after upgrade to ADT 22

Android Activity ClassNotFoundException - tried everything

https://www.youtube.com/watch?v=3vqcGhEPHdo

My solution: naming conflict?

I found through pure desperation that by changing my class name Manifest to MyCoolManifest or something like that, I no longer had the issue. Since your class name is Login, perhaps renaming the class will solve your problem.

Community
  • 1
  • 1
caseyh
  • 448
  • 4
  • 10
  • I had the same issue on Android Studio 3.0 Beta 6. I changed the class name of the activity, ran it and it worked (I just changed the class name back afterwards). Strange issue, I wonder what could've caused it. – Bryan Sep 29 '17 at 18:22
  • What is the reason for waiting two hours? – zuko Sep 13 '18 at 20:13
2

Try cleaning gradle cache & build by running each line in the terminal:

gradlew --stop
gradlew cleanBuildCache
gradlew clean
DoronK
  • 4,837
  • 2
  • 32
  • 37
1

You have to provide:

compileSdkVersion '22' buildToolsVersion "22.0.1" 

as your targetSdkVersion 22

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Saurabh Vardani
  • 1,821
  • 2
  • 18
  • 33
1

Here you go : Clean the project , And uninstall the existing app and run Again .

impathuri
  • 574
  • 6
  • 21
0

For me nothing of the above worked. Until I disabled "Instant Run" to Hot Swap code.

Android studio version: 2.3.3 Latest (at the date of the answer)

Android Test Devices: 5.1.1, 6.0.1

To disable instant run. In Android studio, Got to Preferences -> write "Instant Run" in the search bar -> Uncheck "Enable Instant Run to hot swap code ..."

MBH
  • 16,271
  • 19
  • 99
  • 149
0

Try replacing lambda with anonymous class: java.lang.ClassNotFoundException happened in my android studio project in two classes – in both of them there was lambda expressions. After I replaced lambda with anonymous class – the build was successful.

Udi Reshef
  • 1,083
  • 1
  • 11
  • 14