ClassNotFoundException: Didn't find class on path: DexPathList

我的未来我决定 提交于 2019-12-02 17:30:24

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.

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.

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!

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.

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.

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.

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.

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

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

I added

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

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.

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