简体   繁体   中英

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

I'm developing a chat application, it works for android 21 very good, but on SDK lower 21 as 18 or 19 that cause this problem

11-03 01:49:22.676 20966-20966/ E/AndroidRuntime: FATAL EXCEPTION: main Process: , PID: 20966 java.lang.RuntimeException: Unable to instantiate application .Application: java.lang.ClassNotFoundException: Didn't find class ".Application" on path: DexPathList[[zip file "/data/app/d-9.apk"],nativeLibraryDirectories=[/data/app-lib/-9, /vendor/lib, /system/lib]] at android.app.LoadedApk.makeApplication(LoadedApk.java:516) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4703) at android.app.ActivityThread.access$1600(ActivityThread.java:175) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1368) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:146) at android.app.ActivityThread.main(ActivityThread.java:5602) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283) at com.and roid.internal.os.ZygoteInit.main(ZygoteInit.java:1099) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.ClassNotFoundException: Didn't find class "dev.karim.dardesh.Application" on path: DexPathList[[zip file "/data/app/dev.karim.dardesh-9.apk"],nativeLibraryDirectories=[/data/app-lib/dev.karim.dardesh-9, /vendor/lib, /system/lib]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67) at java.lang.ClassLoader.loadClass(ClassLoader.java:497) at java.lang.ClassLoader.loadClass(ClassLoader.java:457) at android.app.Instrumentation.newApplication(Instrumentation.java:981) at android.app.LoadedApk.makeApplication(LoadedApk.java:511) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4703) at android.app.ActivityThread.access$1600(ActivityThread.java:175) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1368) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:146) at android.app.ActivityThread.main(ActivityThread.java:5602) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099) at dalvik.system.NativeStart.main(Native Method)

and I overridden Attachbasecontext on application class

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);
    }
}

and am using in gradle file:

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

this gradle file:

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'

in addition my project deal with firebase realtime database:

hint/no any solution here is resolve me:

please help me

I had the same issue when I updated Android Studio to 3.0. If you did that too, use the 2.3 version instead. Worked for me!!

Take a look at this guide for extending Application and MultiDex: https://developer.android.com/studio/build/multidex.html

It says:

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

And this answer of mine for other ClassNotFound and multi dex issues: Why is my custom ButtonRenderer not working?

Api 21 makes difference because:

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.

add

        multiDexEnabled true

to your app level build.gradle

将您的班级(应用程序)名称更改为(另一个)名称

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM