ClassNotFoundException: Didn't find class on path: DexPathList
Asked Answered
F

11

36

I have a problem since I updated my App on playstore. Since this update, the exception is thrown, but I haven´t changed anything related to this exception.

Stacktrace:

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{de.opiatefuchs.onthejobtimerlight/de.opiatefuchs.onthejobtimerlight.OnTheJobTimerActivity}: java.lang.ClassNotFoundException: Didn't find class "de.opiatefuchs.onthejobtimerlight.OnTheJobTimerActivity" on path: DexPathList[[zip file "/data/app/de.opiatefuchs.onthejobtimerlight-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2236)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
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:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.ClassNotFoundException: Didn't find class "de.opiatefuchs.onthejobtimerlight.OnTheJobTimerActivity" on path: DexPathList[[zip file "/data/app/de.opiatefuchs.onthejobtimerlight-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:1066)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2226)
... 10 more
Suppressed: java.lang.ClassNotFoundException: de.opiatefuchs.onthejobtimerlight.OnTheJobTimerActivity
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

The thing is, my App version before runs without problems and I haven´t changed anything related to this activity. I´ve just added a new info dialog that has nothing to do with this activity. This app is a free lite version, I´ve made the exact same changes on the pro version and there nothing is thrown. This works as expected. The only difference between pro and lite is, I have integrated Admob (on the new way) in the lite version and Google Play license in the pro version. But this I have integrated since the beginning and haven´t made changes to this. I also haven´t made any changes to the manifest, I read many posts here but nothing helps.

It seems that it just happen on Android versions since 5.0 . Has anybody an idea what this problem could cause or has anybody the same experiences? Is it possible that proguard just destroyed anything by obfuscating (also here, no changes)?

I posted no code, because it is not important to this problem, like I said I haven´t made changes related to this exception.

This Question is marked as duplicate but it isn´t. The comment with the link doesn´t fix my problem, all libraries are checked and integrated in the right way. Also, I don´t use NDK.

Fisher answered 23/4, 2015 at 7:37 Comment(8)
This is no duplicate, as I described because the supposedly duplicated question doesn´t ratio to mine.Fisher
Downvoters! give me a single reason if this question deserve to be downvoted and also to be closed ?Bantling
@TheLittleNaruto...sometimes I wonder if here on SO are poeple who are just downvoting for fun. I see so many times questions with downvotings without an explenation comment and without a reason...Fisher
they must be inexperienced users only.Bantling
@Fisher could you solve this problem? because I get the similar error. But it happened when I tried to import the previous version of my program from backup.Carnassial
Yes and No....I solved it only by trying again and again. After let´s say 10 times it worked. But it happens from time to time again, so there is no recognizable reason for this behavior...Fisher
@Fisher Recently stuck in this problem,same as yours. Keep updating your answer. I upvoted your ques, n dont mind downvoters are suckers who think themselves as genius...Rudman
:) @Crawler, My Answer is still up to date. There was no other solution, it worked like I described and I don´t know why. If You got the same problem, try the things below. If You find another possible issue, than You should post it here....sorry that I can´t give You more help..Fisher
F
26

Update

After a long time, It turned out that it must have anything to do with proguard. I can´t really say what exactly the error causes, but I tried a little bit and that´s what I noticed (that´s in my case with Eclipse IDE):

  • I have to close every tab from the project I want to sign
  • I have to clean the project and after cleaning, do nothing but export the apk
  • Making a small change in manifest, save it and undo the change (and save)
  • If there is any class in manifest named with "YourClass" or ".YourClass", change it to "com.yourpackage.yourClass"

That are the four points I have done and then it worked. This looks suspicious, but I think there is a problem with obfuscating. Because without doing these points, I can simply compile my apk and install it from eclipse. For me, there is no obvious reason for this behavior. Also the package name does work without a change if I only install it from eclipse. I hope these points can help somebody.

Fisher answered 6/5, 2015 at 11:53 Comment(5)
I got the same issue and based on the i reached the same conclusion: proguard. Especially since my non-signed debug builds work just fine. Funny side effect: The messed up signed build results in two icons of the same app! Still trying to find a solution. I am using Android StudioFought
Do You mean like two installed apps in Your device´ app drawer?Fisher
Only one app was installed - but you could see two app icons in the App Launcher. Issue was not related to proguard as I first assumed (or at least not entirely) - the duplicated icons and the missing Class were caused by overriding the AndroidManifest.xml in that particular flavor and having two Launcher Activities xD. I do still have trouble with proguard, but I guess that's just about finding the correct configuration now. Thank you for getting back to me though :) !Fought
This worked for me, I just had to add the full class name to my custom Application class. This error only occurred after moving the project on my local hard drive.Fancier
@Peter....that´s interesting. Well, it was not the case with my project, but it´s anyway good to know.Fisher
P
19

If you manifest package name is ok, If you clossed the project, and within file explorer renamed your project but after importing one you again encounter this problem the only way here is to

DELETE THAT FOLDER .gradle.

This one can be found in project folder using file explorer. It has artifact files that contain that old project's name. After you reopen the project in Android Studio the folder will be recreated automatically.

Phyllys answered 23/6, 2017 at 14:46 Comment(1)
Wow. This was a very specific problem and you had an answer! Thank you so much!Marsh
M
8

I just changed my gradle from com.android.tools.build:gradle:2.2.2 to com.android.tools.build:gradle:2.2.0,and the problem is fine!

Maidenhead answered 15/2, 2017 at 2:28 Comment(1)
You are amazing!Zehe
P
6

For me, it happened when Package name (directory name) was changed.

I realized that "build" folder magically maintains intermediate files for the project build. I deleted "build" folder under "app" folder. Now the gradle had to re-make all files with the new package name. Now it's working correctly.

Pyroligneous answered 16/5, 2017 at 11:16 Comment(0)
D
3

tl;dr: This appears to be caused by the mix of both relative and absolute declaration in the AndroidManifest.xml. I think the best solution is to use relative notation when declaring <application .../>, <activity .../>, <receiver .../>, and <service .../>'s in your AndroidManifest.xml.

Full Explanation:

I had this problem for TOO LONG, it was because I was using both absolute and relative <application .../>, <activity .../>, <receiver .../>, and <service .../> declarations in my AndroidManifest.xml. Here's what I did to fix it:

In you AndroidManifest.xml make sure the <manifest .../> section has it's package: property specified correctly, it'll need to be the exact absolute path, like so:

<manifest
    package="com.my.absolute.package.path"
    xmlns:android="http://schemas.android.com/apk/res/android">...</manifest>

Now that you have the correct absolute path specified in your <manifest .../> section, you'll need to use a relative path for all <application .../>, <activity .../>, <receiver .../>, and <service .../>'s defined in your AndroidManifest.xml.

Examples:

<application
    android:name=".BaseApplication"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <activity
        android:name=".activity.SomeActivity"
        android:configChanges="orientation"
        android:label="@string/app_name"
        android:parentActivityName=".activity.ParentActivity"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value=".activity.ParentActivity"/>
    </activity>

    <activity
        android:name=".activity.MyActivity"
        android:configChanges="orientation"
        android:label="@string/app_name"
        android:parentActivityName=".activity.ParentActivity"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme"
        />

    <receiver
        android:name=".receivers.MyReceiver"
        android:enabled="true"
        android:exported="false">
    </receiver>

    <service
        android:name=".services.MyService"
        android:enabled="true"
        android:exported="false"
        />
</application>

Of course, also be sure to clean you project.

Davidoff answered 19/5, 2016 at 0:38 Comment(0)
A
3

I think it has something to do with multidex and multiple package names if you have multiple modules . Clean the project and delete all build/ folders.

Ahearn answered 24/7, 2016 at 19:29 Comment(0)
M
1

Sometimes when we generate signed apk file, if we have some dependency library issue(duplicate jar library), then this error can occurred. Please check build path and remove duplicate library, and check if any library is not checked from order and export tab.

Multinuclear answered 23/4, 2015 at 9:30 Comment(1)
What do you mean by ~"check build path"? How to check it?Telegraph
C
1

The reason is, android not able to find the specific activity in the dexpath.

So we should provide the entire path of the activities in "Manifest file".

for example your activity name is "SplashActivity" and it is there in " com.packagename.package". So we should provide the entire package name of that activity.

com.packagename.package.SplashActivity
Chesterchesterfield answered 21/11, 2016 at 14:46 Comment(0)
H
0

I had a similar problem, here's my solution:

  1. Change the application name in AndroidManifest to full path
  2. Clean Project
  3. Rebuild Project
  4. Build APK
Hekker answered 9/4, 2017 at 22:46 Comment(0)
R
0

I added

compile "com.android.support:support-core-utils:25.3.1"
compile 'com.android.support:support-v4:25.3.1'
Rocray answered 18/4, 2017 at 11:55 Comment(0)
E
0

I got similar error after change my directory name by simply rename directory name and import. Not able to install anymore. Neither re-enable USB debugging nor Rebuild Project work.

I solve it by create new project and manually copy all relevant content to new project.

Extrorse answered 2/5, 2017 at 7:39 Comment(1)
That might be a long task. Try by deleting app/build folder. It worked for me.Pyroligneous

© 2022 - 2024 — McMap. All rights reserved.