java.lang.ClassNotFoundException:在路径上找不到类“.MyApplication”:DexPathList [[zip file“/data/app/com.sampledemo.box8demo-1/base.apk”]

时间:2017-05-17 12:11:58

标签: android android-gradle classnotfoundexception multidex android-multidex

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

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.access$1600(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.access$1600(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

我在multidex文件中启用了gradle以及在MultiDexApplication类中启用了扩展Application 还在multidex dependecy文件

中添加了gradle

请帮我解决这个问题。

1 个答案:

答案 0 :(得分:0)

好的伙计们,经过多次尝试后我发现你无法在aar文件中添加依赖项。你必须为每个依赖项包含jar。