引起:java.lang.ClassNotFoundException - multidex不能正常工作

时间:2017-12-07 17:33:21

标签: java android multidex

我已经在我的Android应用项目和Google Play Dev"中安装了multidex解决方案。人们会遇到这样的错误:

java.lang.RuntimeException:      
  at android.app.ActivityThread.handleReceiver (ActivityThread.java:2591)     
  at android.app.ActivityThread.access$1700 (ActivityThread.java:157)     
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1450)     
  at android.os.Handler.dispatchMessage (Handler.java:110)     
  at android.os.Looper.loop (Looper.java:193)     
  at android.app.ActivityThread.main (ActivityThread.java:5398)     
  at java.lang.reflect.Method.invokeNative (Native Method)     
  at java.lang.reflect.Method.invoke (Method.java:515)    
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:940)     
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:756)     
  at dalvik.system.NativeStart.main (Native Method)
Caused by: java.lang.ClassNotFoundException:      
  at dalvik.system.BaseDexClassLoader.findClass (BaseDexClassLoader.java:56)     
  at java.lang.ClassLoader.loadClass (ClassLoader.java:497)     
  at java.lang.ClassLoader.loadClass (ClassLoader.java:457)     
  at android.app.ActivityThread.handleReceiver (ActivityThread.java:2586)

据我所知,我已经正确安装了multidex(关于此错误的其他来源& multidex)

我做的事情:

  1. MyApplication类继承自MultiDexApplication
  2. gradle文件:

    android {     defaultConfig {         multiDexEnabled是的     }     dexOptions {         javaMaxHeapSize" 2048M"     } }

    依赖{     编译' com.android.support:multidex:1.0.1' }

  3. 是。我用proguard。

2 个答案:

答案 0 :(得分:0)

更新清单,如:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapp">
    <application
            android:name="android.support.multidex.MultiDexApplication" >
        ...
    </application>
</manifest>

答案 1 :(得分:0)

You need to follow this steps if problem with your MultiDex then it resolve:

Step 1: Add dependency to your app level build.gradle.
defaultConfig {
    multiDexEnabled true
}
dependencies {
    compile 'com.android.support:multidex:1.0.2'
}

step 2: You need to create application class.
public class MyApplication extends Application {

    @Override
    public void onCreate() {
        MultiDex.install(this);
        super.onCreate();
    }

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

}

step 3: You need to Configure MyApplication class to Manifest file.
<application
        android:name=".MyApplication "
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
</application>