【问题标题】:java.lang.ClassNotFoundException: Didn't find class .Application" on path: DexPathListjava.lang.ClassNotFoundException:在路径上找不到类 .Application”:DexPathList
【发布时间】:2017-03-16 11:14:54
【问题描述】:

我正在开发一个聊天应用程序,它适用于 android 21 非常好,但在 SDK 较低 21 为 18 或 19 时会导致此问题

11-03 01:49:22.676 20966-20966/E/AndroidRuntime: 致命例外:主要 进程:,PID:20966 java.lang.RuntimeException:无法实例化应用程序 .Application:java.lang.ClassNotFoundException: 在路径上找不到类“.Application”: DexPathList[[压缩文件 "/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.ActivityThread$H.handleMessage(ActivityThread.java:1368) 在 android.os.Handler.dispatchMessage(Handler.java:102) 在 android.os.Looper.loop(Looper.java:146) 在 android.app.ActivityThread.main(ActivityThread.java:5602) 在 java.lang.reflect.Method.invokeNative(Native Method) 在 java.lang.reflect.Method.invoke(Method.java:515) 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283) 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099) 在 dalvik.system.NativeStart.main(本机方法) 引起: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.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) 在 android.app.ActivityThread.main(ActivityThread.java:5602) 在 java.lang.reflect.Method.invokeNative(Native Method) 在 java.lang.reflect.Method.invoke(Method.java:515) 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283) 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099) 在 dalvik.system.NativeStart.main(Native Method)

我在应用程序类上覆盖了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 实时数据库:

提示/这里没有任何解决方案可以解决我:

请帮帮我

【问题讨论】:

  • 您是否已将 MultiDexApplication 类添加到您的应用程序元素中?
  • 嗨!你找到解决办法了吗?我遇到了同样的问题。

标签: java android firebase


【解决方案1】:

当我将 Android Studio 更新到 3.0 时,我遇到了同样的问题。如果您也这样做了,请改用 2.3 版本。为我工作!

【讨论】:

    【解决方案2】:

    查看本指南以扩展应用程序和 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 和多 dex 问题的回答是:Why is my custom ButtonRenderer not working?

    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.
    

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        猜你喜欢
        • 2014-04-19
        • 1970-01-01
        • 2017-12-23
        • 2018-04-13
        • 2019-07-02
        • 1970-01-01
        • 1970-01-01
        • 2016-06-25
        相关资源
        最近更新 更多