Android ClassNotFoundException: Didn't find class on path
Asked Answered
H

37

102
10-22 15:29:40.897: E/AndroidRuntime(2561): FATAL EXCEPTION: main
10-22 15:29:40.897: E/AndroidRuntime(2561): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.gvg.simid/com.gvg.simid.Login}: java.lang.ClassNotFoundException: Didn't find class "com.gvg.simid.Login" on path: DexPathList[[zip file "/data/app/com.gvg.simid-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.gvg.simid-1, /vendor/lib, /system/lib]]
10-22 15:29:40.897: E/AndroidRuntime(2561):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
10-22 15:29:40.897: E/AndroidRuntime(2561):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
10-22 15:29:40.897: E/AndroidRuntime(2561):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
10-22 15:29:40.897: E/AndroidRuntime(2561):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
10-22 15:29:40.897: E/AndroidRuntime(2561):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-22 15:29:40.897: E/AndroidRuntime(2561):     at android.os.Looper.loop(Looper.java:137)
10-22 15:29:40.897: E/AndroidRuntime(2561):     at android.app.ActivityThread.main(ActivityThread.java:5103)
10-22 15:29:40.897: E/AndroidRuntime(2561):     at java.lang.reflect.Method.invokeNative(Native Method)
10-22 15:29:40.897: E/AndroidRuntime(2561):     at java.lang.reflect.Method.invoke(Method.java:525)
10-22 15:29:40.897: E/AndroidRuntime(2561):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
10-22 15:29:40.897: E/AndroidRuntime(2561):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-22 15:29:40.897: E/AndroidRuntime(2561):     at dalvik.system.NativeStart.main(Native Method)
10-22 15:29:40.897: E/AndroidRuntime(2561): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.gvg.simid.Login" on path: DexPathList[[zip file "/data/app/com.gvg.simid-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.gvg.simid-1, /vendor/lib, /system/lib]]
10-22 15:29:40.897: E/AndroidRuntime(2561):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
10-22 15:29:40.897: E/AndroidRuntime(2561):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
10-22 15:29:40.897: E/AndroidRuntime(2561):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
10-22 15:29:40.897: E/AndroidRuntime(2561):     at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
10-22 15:29:40.897: E/AndroidRuntime(2561):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
10-22 15:29:40.897: E/AndroidRuntime(2561):     ... 11 more

I'm not really sure what is causing it as it is correctly listed in the manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.gvg.simid"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />

    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_LOGS" />
    <uses-permission android:name="android.permission.READ_OWNER_DATA" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.RECORD_AUDIO"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_OWNER_DATA" />
    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />

    <uses-feature android:name="android.hardware.usb.host" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.gvg.simid.Login"
            android:label="@string/app_name" 
            android:screenOrientation="landscape">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

I also added "Android Private Libraries" to build path, and moved it to the top of "Order and Export", but it still gave me the same error.

EDIT: I rebuilt the project completely, and was unable to reproduce the error. Not sure what was causing it.

Haldes answered 22/10, 2013 at 16:17 Comment(7)
are you using proguard?Samaveda
Proguard is not enabled.Haldes
Check this post: #10866931Samaveda
try ".Login" in android:name instead, Android will append the rest of the prefix by itself if it can't detect it. Could just be a weird parsing issue with EclipseBrassie
@Samaveda I read that post before making this one, but unfortunately everything I tried from there did not work.Haldes
@DarrylBayliss yeah tried that too, but didn't fix it.Haldes
If you are using Cleanmaster or similar apps on your device, try uninstalling itTremml
L
78

I had the same issue for my project. It happened due to the conflict in android support library version between my project and the library project that I added in my project. Put the same version android support library in your project and library projects you included and clean build... Everything will work...

Lux answered 26/3, 2014 at 5:22 Comment(4)
Thanks man!!! I was sure I had already done it, but I checked and the versions were different! Thanks a lot!Abortive
i comment this to remember next time to "update" sdk, watch this answerHairpin
Any ideas why problem happen if I don't use support libraries?Craniometer
In my case it's a Didn't find class "android.graphics.ColorSpace" error. There should be no conflict in Android SDK.Merchandising
M
33

This following method worked for me

  • Right click on your project and select properties
  • The "Properties for " panel will open. From the menu on the left go to Java Build Path -> Order and Export
  • From the list below uncheck the box next to "Android Dependencies"
  • Finally clean your project and run
Marsland answered 22/1, 2014 at 17:58 Comment(4)
That worked for me. What is the meaning of "Android Dependencies" and why did it help in this particular case?Shed
Are these instructions for eclipse? I can't follow these instructions for android studio. What is my project? What does that mean?Assumption
Yes these instructions are for eclipseMarsland
This link has steps for Android Studio #18533554Aguish
R
14

For those of you who are having this issue on Android Studio, I had the same problem after a merge and for some reason it even persisted after clean and invalidate cash/restart operations which was driving me crazy.

Turns out, it can be fixed by running gradle build once from command line. Simply run the following n the project directory:

./gradlew assemble clean
./gradlew assemble

I hope it'd save someone the time waste and frustration I had to go through.

Radcliff answered 31/5, 2017 at 11:24 Comment(1)
Worked for me tooPlater
R
13

I had same issue, this worked for me

1) Full path of activity in mainfest in place of relative path.

2) Delete 'build' folder and clean project.

Recall answered 29/6, 2016 at 7:4 Comment(3)
Deleting the build folder worked for me. I lost a few hours on this issue, Thank youTragedian
Worked for me too. Thanks.Kioto
This is the real deal. XDLeeleeann
I
10

If you added a new Library Project as a module to your Android project and you're using Kotlin in your library do not forget to add

apply plugin: 'kotlin-android'

to top of your module's Gradle file. Android Studio does not add this line when you created a new module and this may waste your hours like me.

Edit: After a while, I just struggled with this problem again and this time I forgot to add my module as a dependency on the project. :)

Imco answered 17/12, 2018 at 15:24 Comment(3)
Solved it for me and I just wanted to post an answer. Who skips to page two on SO for a solution?Vickivickie
This issue happens when we use java library project ... this solution fixed my problemWasp
This worked for me and clued me in to the fact that I was missing classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"Purehearted
H
9

If you are using Eclipse try Project -> Clean

Hanna answered 22/10, 2013 at 16:25 Comment(1)
Works for android studio - Clean / Rebuild project and runOisin
P
7

This happens if we change Build Path of the APP, this can be in any case of Adding or Removing or Changing Libraries or .jar file. The Best solution is to Restart the Eclipse.

Pennyroyal answered 28/1, 2014 at 8:39 Comment(0)
O
6

If you get this error while using the new Instant Run feature in Android Studio 2.0 and above then this is some kind of bug on their side.
To fix this you will have to stop your app manually on Device/Emulator if it's not stopped then from Android Studio select BuildRebuild Project.
Then click the Run button or SHIFT+F10

Obloquy answered 17/4, 2016 at 13:27 Comment(0)
C
6

For any one who is having multidex enable write this

inside build.gradle

apply plugin: 'com.android.application'

android {
 defaultConfig {
      multiDexEnabled true
  }
 dexOptions {
        javaMaxHeapSize "4g"
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:+'
    compile 'com.google.android.gms:play-services:+'
    compile 'com.android.support:multidex:1.0.1'
}

write a class EnableMultiDex like below

import android.content.Context;
import android.support.multidex.MultiDexApplication;

public class EnableMultiDex extends MultiDexApplication {
    private static EnableMultiDex enableMultiDex;
    public static Context context;

    public EnableMultiDex(){
        enableMultiDex=this;
    }

    public static EnableMultiDex getEnableMultiDexApp() {
        return enableMultiDex;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        context = getApplicationContext();

    }
}

and in AndroidManifest.xml write this className inside Application tag

 <application
    android:name="YourPakageName.EnableMultiDex"
    android:hardwareAccelerated="true"
    android:icon="@drawable/wowio_launch_logo"
    android:label="@string/app_name"
    android:largeHeap="true"
    tools:node="replace">
Crunode answered 5/1, 2017 at 7:29 Comment(4)
ohhhhh mahn...perfect answer..i saw this answer but no one has voted so i neglected this and went for voted answers but not worked..finally i just tested this one and i got it ,thanks mahn.:):):):)Import
glad it helped :)Crunode
The main point is to extend application from MultiDexApplication class instead of Application.Zonazonal
Thanks. I already had some Application in Manifest. Extended it from MultiDexApplication, and exception disappeared on Android 4.4.Transfiguration
G
6

If you are using Multidex on Android 4.4 and prior, your issue might be that your activity class is located in the second dex file and therefore not found by the android system.

To keep your activity class in the main dex file, see this page:

https://developer.android.com/studio/build/multidex.html#keep


To find which classes are located in a dex file use Android Studio.

Simply drag n drop your apk into Android Studio. You should be able to see your dex files in the apk explorer.

Then select the dex file to see what classes are inside.


another alternative is dexdump:

You can check the content of your dex files contained in your apk by using the command dexdump which can be found in

android-sdk/build-tools/27.0.3/dexdump

For windows users see this tool I made to ease the process

Gulch answered 28/12, 2017 at 16:34 Comment(1)
When linking your own tool, be sure to declare you own it.Jalap
L
6

In my case it was proguard minification process that removed some important classes from my production apk.

The solution was to edit the proguard-rules.pro file and add the following:

-keep class com.someimportant3rdpartypackage.** { *; }
Landbert answered 2/4, 2018 at 1:55 Comment(2)
this is cause with my current crash. but do u know a way to get the name of classes should be kept?Christoperchristoph
It's been a while, but I'm guessing you can see from the crash what classes were removed and keep themLandbert
A
3

1) Create libs folder under project root
2) Copy and paste the jar file into it
3) Configure the build path (Add jar)
4) Clean and run

cheers :-)

Abelabelard answered 24/12, 2014 at 6:51 Comment(0)
W
3

I faced this error once when I defined a class that extended a view but referred to this custom view in the layout file with the wrong name. Instead of <com.example.customview/>, I had included <com.customview/> in the XML layout file.

Wellbalanced answered 11/7, 2015 at 5:46 Comment(0)
T
3

Believe me or not... I tried out almost each answer I had found here on stackoverflow. Nothing would help, until I just restarted the machine. My Android Studio works on Ubuntu 16.04 LTS.

Trillbee answered 5/1, 2017 at 2:22 Comment(1)
Same here, tried all and restart following your comment. I saw in my output a reference a to refactored class name that "Couldn't be found" despite I erase the whole build folder.. just starting androidShwalb
J
2

I met the same problem and I noticed the sample code was put under directory "java" instead of directory "src". After moving the code to src, the problem was solved.

Also make sure the app directory is split into multiple folders. e.g. /main/com/site/appname/ not /main/com.site.appname/

Hope it works~

Jaundice answered 14/3, 2014 at 1:18 Comment(1)
You nailed the problem I had on the head! Not enough sleep, didn't even realize that classes were in the Java folder :)Nomanomad
K
2

I faced the same problem and solved it by doing the following:

From the build menu select

1- clean Project.

2- Build APK.

Kremer answered 23/9, 2017 at 4:49 Comment(1)
I always spend hours looking for solution on SO and turns out Clean -> Build is all I had to do.Tuckie
P
2

I face the same problem , and after a lot of work and search , I figured out the solution : I just cleaned the project then build the apk. -Build->Clean Project -Build-> Build APK(s) I hope it is useful.....

Photodisintegration answered 24/5, 2019 at 22:1 Comment(0)
D
1

I had this issue recently and I am using Android Studio 0.8.4

The problem was the fact that I decided to rename an XML menu layout file that was called main.xml.

Right click on it and chose Refactor --> Rename. Before renaming it, be sure uncheck "Search in comments and strings" and pressed Refactor.

Because my file was originally named 'main', it renamed critical paths in the app.iml and build.gradle, mainly the java.srcDirs in the build.gradle, since the path is defined as 'src/main/java'.

I hope this helps anyone that may be experiencing this issue.

Dekaliter answered 8/8, 2014 at 18:57 Comment(0)
A
1

I had this problem after upgrading from version 18. After the upgrade I had the following: Project Build Target was 5.01, targetSDKVersion=21

But: Build Tools were still from Android 4.3.1 (18) What I noticed was that those apps that were deriving their activities from ActionBarActivity crashed with the above error those that did not still ran.

So the simple fix was to use the latest Android SDK Build Tools 21.1.2 instead of only those of Android SDK Build Tools 18, which seems somehow the default.

So the culprit seems the Appcompat library, which I use for Actionbar backward compability.

And a by the way: using the appcompat library I had to set/fix: $SDKInstallDIR$\Android\android-sdk\extras\android\support\v7\appcompat\project.properties target=android-21 (which was recommended in some other useful post and which has a value of 19 by default))

Alfonzoalford answered 28/1, 2015 at 16:38 Comment(0)
V
1

I had this problem several times and often I didn't do something obviously wrong with dependencies.

It's always a good idea to check if this 'not found' class is present in the final apk. If it is, like it happened in my cases, the problem usually is:

It's not that given class is not found, but it cannot be loaded because its super class is missing.

Check if class that you extend is available and then try to fix your build script or dependencies accordingly.

Viens answered 22/2, 2017 at 11:32 Comment(0)
B
1

I had the same issue on Windows. I had renamed the path to the project to something containing a space.

Make sure the path to your project does not contain a space.

Bricole answered 23/4, 2017 at 19:39 Comment(1)
What path are you talking about?Suilmann
M
1

Solution mentioned here --> Multidex Issue solution worked for me. Below is what needs to be added to Application context :

@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}
Mischance answered 13/12, 2017 at 4:21 Comment(0)
Y
0

I had this issue, raised by several causes, but i see this in your stacktrace "**Unable to instantiate activity ComponentInfo{...}: java.lang.ClassNotFoundException: Didn't find class "..." on path: DexPathList[[**", I found a diference in my .classpath before it stop working.

 <?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
    <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
    <classpathentry kind="src" path="gen"/>
    <classpathentry kind="output" path="bin/classes"/>
</classpath>

I've ADDED the line:

<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>

this is the final version:

  <?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
    <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
    <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
    <classpathentry kind="src" path="gen"/>
    <classpathentry kind="output" path="bin/classes"/>
</classpath>

Now it works! =)

Yale answered 30/1, 2014 at 21:57 Comment(0)
N
0

I had the same exact issue. As @weiweia suggested, move the code from the java directory to src worked for me. I also removed the Android Dependencies from Project --> Properties --> Java Build Path --> Order and Export, and made sure only to include Library Projects in the Android screen.

Nomanomad answered 15/7, 2014 at 20:49 Comment(0)
F
0

I had this problem for quite a while, and like everybody else the answers above didn't apply to my project.

In my project I had linked up a project to my project and it was throwing ClassDefNotFoundError every time some code for the other project was executed.

So this was my solution. I went to project properties of my project and Java Build Path. Pressed the "Source"-tab and "link source" from src-folder of the other project to my own project and named a new folder "core-src".

Hopes this solution helps someone

Foilsman answered 14/8, 2014 at 7:55 Comment(0)
S
0

I had the same issue. I am using Xamarin.Android.

The problem in my case was that I changed the versionCode and versionName.

I had no problem when I had them set like this:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="pac.ka.ge" android:versionCode="1" android:versionName="1.0" android:installLocation="auto">

The issue appeared when I changed it to this (versionCode 2 and versionName 0.0.1):

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package=" pac.ka.ge " android:versionCode="2" android:versionName="0.0.1" android:installLocation="auto">

I fixed the issue by changing to versionCode 2 and versionName 1.0.0.1, like so:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package=" pac.ka.ge " android:versionCode="2" android:versionName="1.0.0.1" android:installLocation="auto">

I am unsure why this was a problem, maybe Android doesn't like a lower versionName with a higher versionCode?

I found the following on http://developer.android.com/guide/topics/manifest/manifest-element.html#vname

android:versionCode An internal version number. This number is used only to determine whether one version is more recent than another, with higher numbers indicating more recent versions. This is not the version number shown to users; that number is set by the versionName attribute. The value must be set as an integer, such as "100". You can define it however you want, as long as each successive version has a higher number. For example, it could be a build number. Or you could translate a version number in "x.y" format to an integer by encoding the "x" and "y" separately in the lower and upper 16 bits. Or you could simply increase the number by one each time a new version is released.

android:versionName The version number shown to users. This attribute can be set as a raw string or as a reference to a string resource. The string has no other purpose than to be displayed to users. The versionCode attribute holds the significant version number used internally.

Semiaquatic answered 30/10, 2014 at 11:5 Comment(0)
N
0

Just in case anybody faces the same problem as me and no suggest answer here helps.

For me the cause was, that the Android studio refactor is buggy. I moved an innerclass outside of a class, which was a View and therefore also had a xml, where the direct path was set. This path will not get refactored by studio! And no error will be thrown.

Hope this helps anybody. Cheers.

Neelyneeoma answered 21/1, 2015 at 21:22 Comment(0)
C
0

In our case we wanted to compile Vagrant version and had same error. We fixed it by clean project and rebuild project in Build menu

Cookery answered 19/5, 2015 at 8:18 Comment(0)
R
0

I just restarted the device and ran the app. It worked without any issues. Hope this helps someone :)

Restless answered 30/5, 2016 at 9:43 Comment(0)
P
0

I found this error in Android Studio when i tried do debug in a device with API 23, so i checked the Android Studio and i noticed that i didnt had instaled this API 23 version. After install, i solved the problem.

Personalty answered 9/2, 2017 at 1:22 Comment(0)
A
0

I also faced the same problem, we can solve this by doing some thing like

1- Uninstall the app.

2- Rebuild the project.

3- Clean the project.

4- Invalidate and restart the project from file -> invalidate and restart.

Alva answered 27/3, 2017 at 6:23 Comment(0)
C
0

I ran into the same issue. I solved it by first deleting the build folder in your android project folder and the build folder in your app folder. then clean your project and build.

Consuelaconsuelo answered 7/4, 2017 at 13:34 Comment(0)
G
0

java.lang.RuntimeException: Unable to instantiate application com.android.tools.fd.runtime.BootstrapApplication: java.lang.ClassNotFoundException: Didn't find class "com.android.tools.fd.runtime.BootstrapApplication" on path: /data/app.apk(in android 4.3, 4.1)

Unable to instantiate application com.android.tools.fd.runtime.BootstrapApplication: java.lang.ClassNotFoundException: com.android.tools.fd.runtime.BootstrapApplication(in below lollipop iam facing like this error)

To disable Instant Run, it will work fine follow the below steps to disable instant run in android studio 1. Go to File Settings--> Build,Execution,Deployment -->Instant Run ---> uncheck "Enable instant run"

Grory answered 20/6, 2017 at 5:0 Comment(0)
L
0

I faced this problem when I tried to build and install my app to a Android 8.1.0 (API 26)phone.

The only reason is that I added android:hasCode="false" to the application tag in the manifest file. However, it worked on API 24 with the same code when I tried several months ago (STRANGE?).

After removing that attribute, the problem disappears.

Lawtun answered 23/2, 2018 at 7:42 Comment(0)
V
0

I was having the same issue today. And tried all the above solutions already given but nothing worked for me. Then I spent sometime and I found out the reason. I thought it could save some other developers time I am sharing here as well. The problem was with wrong package name. I was using MVP architecture, and I kept my activities in view package. And I copied the Main class from my other project. This was the catch. In the xml, Main Activity was referring to different Package that was just outer side. The package was not including my view directory (MVP hierarchy level). Then I checked back in manifest as well. The same problem I found there as well. So I provided full path(package name) of my activity(untill MVP' view directory/package there I kept my all activities). This solved my problem. Hope that helps others as well.

Vespucci answered 17/9, 2018 at 11:20 Comment(0)
P
0

I had a similar problem for Android 4 Phone, but worked for versions above this. I had added "multidexEnabled=true" line to gradle script due to some reasons before. And now I deleted this line and it worked for both versions (Android 4 and above). But I didn't understand why I added that line and how it works now.

Polyzoic answered 3/7, 2020 at 15:54 Comment(0)
A
-1

I had this issue in IntelliJ IDEA. This is how I solved it:

Project Properties > Facets > Click the Android Facet created from the external library you are adding > Check the box 'Library Module'.

Antirachitic answered 23/11, 2014 at 17:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.