java.lang.ClassNotFoundException:未在路径中找到 class“.MyApplication”:DexPathList[[zip 文件“/data/app/com.sampledemo.box8demo-1/base.apk”]

java.lang.ClassNotFoundException: Didn't find class ".MyApplication" on path: DexPathList[[zip file "/data/app/com.sampledemo.box8demo-1/base.apk"]

从 3 天开始,我一直在尝试解决以下问题。 问题:在 android 项目中创建新模块作为库并使用 assembleDebug 创建 aar 文件。 我在另一个项目中添加的那个 aar 文件作为一个新模块(依赖项也添加了)但是在将应用程序安装到设备后我得到以下错误:

6055-26055/com.sampledemo.box8demo E/AndroidRuntime: FATAL EXCEPTION: main
        Process: com.sampledemo.box8demo, PID: 26055
        java.lang.RuntimeException: Unable to instantiate application com.NerdNow.NerdNowApplication: java.lang.ClassNotFoundException: Didn't find class "com.NerdNow.NerdNowApplication" on path: DexPathList[[zip file "/data/app/com.sampledemo.box8demo-1/base.apk"],nativeLibraryDirectories=[/data/app/com.sampledemo.box8demo-1/lib/arm64, /vendor/lib64, /system/lib64]]
        at android.app.LoadedApk.makeApplication(LoadedApk.java:580)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4699)
        at android.app.ActivityThread.access00(ActivityThread.java:153)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1412)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:5441)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)
        Caused by: java.lang.ClassNotFoundException: Didn't find class "com.NerdNow.NerdNowApplication" on path: DexPathList[[zip file "/data/app/com.sampledemo.box8demo-1/base.apk"],nativeLibraryDirectories=[/data/app/com.sampledemo.box8demo-1/lib/arm64, /vendor/lib64, /system/lib64]]
        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.newApplication(Instrumentation.java:982)
        at android.app.LoadedApk.makeApplication(LoadedApk.java:575)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4699)
        at android.app.ActivityThread.access00(ActivityThread.java:153)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1412)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:5441)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)
        Suppressed: java.lang.NoClassDefFoundError: com.NerdNow.NerdNowApplication
        at dalvik.system.DexFile.defineClassNative(Native Method)
        at dalvik.system.DexFile.defineClass(DexFile.java:226)
        at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:219)
        at dalvik.system.DexPathList.findClass(DexPathList.java:338)
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
        ... 13 more
        Suppressed: java.lang.ClassNotFoundException: com.NerdNow.NerdNowApplication
        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

我在 gradle 文件中启用了 multidex 并在 Application class 中扩展了 MultiDexApplication 还在 gradle 文件

中添加了 multidex dependecy

请帮我解决这个问题。

好的伙计们,经过多次尝试我发现你不能添加对 aar 文件的依赖。您必须为每个依赖项包含 jar。