MultiDex应用程序:启用库时的java.lang.ClassNotFoundException

时间:2018-05-14 23:09:40

标签: android build android-gradle

我正在使用Android Studio 3.1.2& Gradle 3.1.2& minSdkVersion 19& compileSdkVersion 26并在运行Nougat的模拟器和运行Oreo的智能手机上进行了测试,并在启动应用后获得此异常

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.***.***.****, PID: 16366
    java.lang.RuntimeException: Unable to instantiate application com.***.***.***.view.application.MyApplicationClass: java.lang.ClassNotFoundException: Didn't find class "com.***.***.***.view.application.MyApplicationClass" on path: DexPathList[[zip file "/data/app/com.***.***.***-2/base.apk"],nativeLibraryDirectories=[/data/app/com.***.***.***-2/lib/x86, /data/app/com.***.***.***-2/base.apk!/lib/x86, /system/lib, /vendor/lib]]
        at android.app.LoadedApk.makeApplication(LoadedApk.java:802)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5377)
        at android.app.ActivityThread.-wrap2(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1545)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6119)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.***.***.***.view.application.MyApplicationClass" on path: DexPathList[[zip file "/data/app/com.***.***.***-2/base.apk"],nativeLibraryDirectories=[/data/app/com.***.***.***-2/lib/x86, /data/app/com.***.***.***-2/base.apk!/lib/x86, /system/lib, /vendor/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at android.app.Instrumentation.newApplication(Instrumentation.java:992)
        at android.app.LoadedApk.makeApplication(LoadedApk.java:796)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5377) 
        at android.app.ActivityThread.-wrap2(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1545) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.app.ActivityThread.main(ActivityThread.java:6119) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 
  • MyApplicationClass扩展MultiDexApplication
  • 我在清单文件android:name=".view.application.MyApplicationClass"
  • 中注册了该课程
  • 我使用gradle.build
  • multiDexEnabled true中启用MultiDex
  • 我使用compile 'com.android.support:multidex:1.0.2'进行向后兼容
  • 我使用SOASTA mPulse library进行效果监控

当我使用apply plugin: 'com.soasta.mpulse.android' 启用此库时会发生异常,否则应用程序正常

我尝试了很多解决方案但没有一个正在运行:

现在试图解决这个问题2天了,任何帮助都会非常感激

1 个答案:

答案 0 :(得分:-1)

我发现解决方案是添加的 机器人:名称=" android.support.multidex.MultiDexApplication"到AndroidManifest.xml

<div class="col-sm-12">
    <input name="name" id="name" placeholder="Dein Name *"/>
</div>
<div class="col-sm-6">
    <input name="email" id="email" placeholder="Deine E-Mailadresse *"/>
</div>
<div class="col-sm-6">
    <input name="phone" id="phone" placeholder="Deine Telefonnummer"/>
</div>
<div class="col-sm-12"> 
    <textarea name="message" rows="9" id="message" placeholder="Gib hier deine Nachricht ein *"></textarea>
</div>
<div class="col-md-12">
    <input type="submit" class="submit btn btn-lg btn-primary" id="submit" value="Nachricht senden"/>
</div>
</form>