android – 在路径上找不到类:DexPathList?

当我在Android studio中使用USB在真实设备中测试时,我的应用程序工作正常.但是当我将apk发送到另一台设备并安装在那里时,它无法正常工作.App得到崩溃.我没有找到任何正确的方法来解决问题.错误如下:

FATAL EXCEPTION: main Process: com.w3xplorers.cmch,PID: 17715                                                                           java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.w3xplorers.cmch/com.w3xplorers.cmch.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.w3xplorers.cmch.MainActivity" on path: DexPathList[[zip file "/data/app/com.w3xplorers.cmch-1/base.apk"],nativeLibraryDirectories=[/data/app/com.w3xplorers.cmch-1/lib/arm, /system/lib, /vendor/lib, system/vendor/lib, system/vendor/lib/egl, system/lib/hw]]
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2395)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2544)
    at android.app.ActivityThread.access$900(ActivityThread.java:150)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1394)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:168)
    at android.app.ActivityThread.main(ActivityThread.java:5845)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:797)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
    Caused by: java.lang.ClassNotFoundException: Didn't find class "com.w3xplorers.cmch.MainActivity" on path: DexPathList[[zip file "/data/app/com.w3xplorers.cmch-1/base.apk"],nativeLibraryDirectories=[/data/app/com.w3xplorers.cmch-1/lib/arm, /system/lib, /vendor/lib, system/vendor/lib, system/vendor/lib/egl, system/lib/hw]]
    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:1085)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2385)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2544) 
    at android.app.ActivityThread.access$900(ActivityThread.java:150) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1394) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:168) 
    at android.app.ActivityThread.main(ActivityThread.java:5845) 
    at java.lang.reflect.Method.invoke(Native Method) 
    atcom.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)                                                                         Suppressed: java.lang.ClassNotFoundException: com.w3xplorers.cmch.MainActivity
    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)                                                                                ... 12 more
    Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available

我的清单如下:

`<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.w3xplorers.cmch">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.SEND_SMS" />


<application
    android:name="com.w3xplorers.cmch.EnableMultiDex"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.w3xplorers.cmch.MainActivity"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBar" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.w3xplorers.cmch.HomeActivity"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBar" />
    <activity
        android:name="com.w3xplorers.cmch.QuickSms"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBar" />
    <activity
        android:name="com.w3xplorers.cmch.GroupSms"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBar" />
    <activity
        android:name="com.w3xplorers.cmch.SelfSms"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBar" />
    <activity
        android:name="com.w3xplorers.cmch.Contact"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBar" />
    <activity
        android:name="com.w3xplorers.cmch.Favourite"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBar" />
    <activity
        android:name="com.w3xplorers.cmch.Info"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBar" />
    <activity android:name="com.w3xplorers.cmch.Dialog" />
</application>

</manifest>`

Gradle如下:

apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
    applicationId "com.w3xplorers.cmch"
    minSdkVersion 13
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    multiDexEnabled true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}


dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', 
{
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.0'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha5'
compile 'com.android.support:design:25.3.0'
compile 'com.andreabaccega:android-form-edittext:1.0.3'
compile 'com.android.volley:volley:1.0.0'
compile 'com.squareup.okhttp3:okhttp:3.3.1'
compile 'com.android.support:multidex:1.0.1'
testCompile 'junit:junit:4.12'
}

解决方法:

转到项目级build.gradle文件,并将gradle依赖的版本减少到低于2.3.0的任何值,比如使用2.2.3

dependencies {
    classpath 'com.android.tools.build:gradle:2.2.3'
    ....
}

然后清理 – > build – >将debug apk安装到其他设备 – >它可能就行了!

上一篇:Hbuild在线云ios打包失败,提示BuildConfigure Failed 31013 App Store 图标 未找到 解决方法


下一篇:java – Android:以编程方式更改App Label