ClassNotFoundException: Didn't find class on path: DexPathList

£可爱£侵袭症+ 提交于 2019-12-20 08:57:13

问题


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.


回答1:


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.




回答2:


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.




回答3:


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!




回答4:


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.




回答5:


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.




回答6:


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.




回答7:


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.




回答8:


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



回答9:


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



回答10:


I added

compile "com.android.support:support-core-utils:25.3.1"
compile 'com.android.support:support-v4:25.3.1'



回答11:


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.



来源:https://stackoverflow.com/questions/29816745/classnotfoundexception-didnt-find-class-on-path-dexpathlist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!