簡體   English   中英

java.lang.ClassNotFoundException:在路徑:DexPathList上找不到類“ .Application”

[英]java.lang.ClassNotFoundException: Didn't find class .Application" on path: DexPathList

我正在開發一個聊天應用程序,它非常適用於android 21,但在SDK較低的21(例如18或19)上會導致此問題

11-03 01:49:22.676 20966-20966 / E / AndroidRuntime:FATAL EXCEPTION:main Process:,PID:20966 java.lang.RuntimeException:無法實例化應用程序.Application:java.lang.ClassNotFoundException:未找到類路徑上的“ .Application”:DexPathList [[zip文件“ /data/app/d-9.apk"],nativeLibraryDirectories=[/data/app-lib/-9,/ vendor / lib,/ system / lib]]在android.app.LoadedApk.makeApplication(LoadedApk.java:516)在android.app.ActivityThread.handleBindApplication(ActivityThread.java:4703)在android.app.ActivityThread.access $ 1600(ActivityThread.java:175)在android.app .android.os.Handler.dispatchMessage(Handler.java:102)的.ActivityThread $ H.handleMessage(ActivityThread.java:1368)在android.app.ActivityThread的android.os.Looper.loop(Looper.java:146)處。 com.android.internal.os.ZygoteInit $上java.lang.reflect.Method.invoke(Method.java:515)上的main(ActivityThread.java:5602) MethodAndArgsCaller.run(ZygoteInit.java:1283)位於com.and dalvik.system.NativeStart.main(本機方法)處的roid.internal.os.ZygoteInit.main(ZygoteInit.java:1099)原因:java.lang.ClassNotFoundException:找不到類“ dev.karim.dardesh.Application” “在路徑上:DexPathList [[zip文件“ /data/app/dev.karim.dardesh-9.apk"],nativeLibraryDirectories=[/data/app-lib/dev.karim.dardesh-9、/vendor/lib, / system / lib]]在dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)在java.lang.ClassLoader.loadClass(ClassLoader.java:497)在java.lang.ClassLoader.loadClass(ClassLoader.java:457 )在android.app.Instrumentation.newApplication(Instrumentation.java:981)在android.app.LoadedApk.makeApplication(LoadedApk.java:511)在android.app.ActivityThread.handleBindApplication(ActivityThread.java:4703)在android.app android.app.ActivityThread.access $ 1600(ActivityThread.java:175)在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1368)在android.os.Handler.dispatchMessage(Handler.java:102)在android.os.Looper .loop(Looper.java:146)在 com.android的java.lang.reflect.Method.invokeNative(本機方法)處的android.app.ActivityThread.main(ActivityThread.java:5602)。在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)處的internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1283)在dalvik.system.NativeStart.main(本機方法)處

我在應用程序類上覆蓋了Attachbasecontext

public class Application extends android.app.Application{
    @Override
    public void onCreate() {
        super.onCreate();
        Firebase.setAndroidContext(this);
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
}

並在gradle文件中使用:

multiDexEnabled true
    compile 'com.android.support:multidex:1.0.1'

此gradle文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.3"

    defaultConfig {
        applicationId "pakage.com"
        minSdkVersion 17
        targetSdkVersion 24
        versionCode 18
        versionName "18"
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"


        jackOptions {
            enabled true
            additionalParameters('jack.incremental': 'true')
        }
    }

    compileOptions {
        incremental true
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    dexOptions {
        preDexLibraries = false
        javaMaxHeapSize '4096m'
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

        }
    }



    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE-FIREBASE.txt'
    }




}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.firebase:firebase-client-android:2.3.1'
    compile 'com.android.support:design:24.2.1'
    compile 'com.android.support:recyclerview-v7:24.2.1'
    compile 'com.android.support:cardview-v7:24.2.1'
    compile 'com.squareup.picasso:picasso:2.5.0'
    compile 'com.android.support:support-v4:24.2.1'
    compile 'com.google.android.gms:play-services-ads:9.8.0'
    compile 'com.google.firebase:firebase-messaging:9.8.0'
    compile 'com.google.firebase:firebase-auth:9.8.0'
    compile 'com.google.android.gms:play-services:9.8.0'
    compile 'com.google.firebase:firebase-core:9.8.0'
    compile 'com.google.firebase:firebase-database:9.8.0'
    compile 'com.android.support:multidex:1.0.1'
    testCompile 'junit:junit:4.12'
    compile 'com.google.android:support-v4:r7'
}


apply plugin: 'com.google.gms.google-services'

另外我的項目處理的是Firebase實時數據庫:

提示/沒有任何解決方案可以解決我的問題:

請幫我

我將Android Studio更新到3.0時遇到了同樣的問題。 如果您也這樣做,請改用2.3版本。 為我工作!

看看此擴展應用程序和MultiDex的指南: https : //developer.android.com/studio/build/multidex.html

它說:

If you do override the Application class, change it to extend MultiDexApplication (if possible) as follows

我的其他ClassNotFound和multi dex問題的答案是: 為什么我的自定義ButtonRenderer無法正常工作?

Api 21之所以與眾不同,是因為:

Android 5.0 (API level 21) and higher uses a runtime called ART which natively supports loading multiple DEX files from APK files. ART performs pre-compilation at app install time which scans for classesN.dex files and compiles them into a single .oat file for execution by the Android device. Therefore, if your minSdkVersion is 21 or higher, you do not need the multidex support library.

        multiDexEnabled true

到您的應用程序級別build.gradle

將您的班級(應用程序)名稱更改為(另一個)名稱

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM