在某些设备上,Android应用程序崩溃并出现ClassNotFoundException

时间:2017-07-13 07:27:06

标签: android classnotfoundexception android-multidex

您好我正在开发andorid applicaiton。我试图在某些设备上安装此应用程序。它工作正常。但在其他一些设备上它崩溃有以下例外:

07-13 12:28:17.515 17306-17306/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.simple, PID: 17306
java.lang.RuntimeException: Unable to instantiate application 
com.example.simple.SampleApplication: java.lang.ClassNotFoundException: 
Didn't find class "com.example.simple.SampleApplication" on path: 
DexPathList[[zip file 
"/data/app/com.example.simple-1/base.apk"],nativeLibraryDirectories=[/data/ap
p/com.example.simple-1/lib/arm, 
/data/app/com.example.simple-1/base.apk!/lib/armeabi-v7a, /vendor/lib, 
/system/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:608)
at 
android.app.ActivityThread.handleBindApplication(ActivityThread.java:5013
)
at android.app.ActivityThread.-wrap1(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1572)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5847)
at java.lang.reflect.Method.invoke(Native Method)
at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.jav
a:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.ClassNotFoundException: Didn't find class 
"com.example.simple.SampleApplication" on path: DexPathList[[zip file 
"/data/app/com.example.simple-1/base.apk"],nativeLibraryDirectories=[/data/a
pp/com.example.simple-1/lib/arm, 
/data/app/com.example.simple-1/base.apk!/lib/armeabi-v7a, /vendor/lib, 
/system/lib]]
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:986)
at android.app.LoadedApk.makeApplication(LoadedApk.java:603)
at 
android.app.ActivityThread.handleBindApplication(ActivityThread.java:5013
) 
at android.app.ActivityThread.-wrap1(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1572) 
at android.os.Handler.dispatchMessage(Handler.java:111) 
at android.os.Looper.loop(Looper.java:207) 
at android.app.ActivityThread.main(ActivityThread.java:5847) 
at java.lang.reflect.Method.invoke(Native Method) 
at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.jav
a:865) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
Suppressed: java.lang.ClassNotFoundException: 
com.example.simple.SampleApplication
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
07-13 12:33:17.714 17306-17306/com.example.simple I/RuntimeInit: RuntimeInit: enable FTRACE

我已经在我的gradle中启用了multiDexEnabled true。需要一些帮助来解决这个问题。谢谢。

3 个答案:

答案 0 :(得分:1)

在依赖项标记下添加以下链接:

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

同步并运行......

答案 1 :(得分:0)

在build.gradle文件中

    dependencies {

       ...
        //Multi Dex
        compile 'com.android.support:multidex:1.0.1'
       ....
    }

在示例应用程序类

 @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(SampleApplication.this);
    }

然后清洁&建立项目

答案 2 :(得分:0)

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

为我工作...... 我试图从mac运行应用程序(在Windows上构建)。 它在应用程序启动时崩溃。

谢谢大家..