Frequently problem solutions of the Multidex framework in the Java library

Frequently problem solutions of the Multidex framework in the Java library Overview: When the number of methods used in the Android application exceeds the limit of the DEX compiler, an error of the "65536 method limit" will occur.To solve this problem, using the Multidex framework can enable applications to support more than 65,536 methods.This article will introduce a common problem solving method in the process of using the Multidex framework in the Java library. 1. Question: No Field Dexpathlist.pathlist. Error details: java.lang.nosuchfieldException: No Field Dexpathlist.Pathlist in class LDALVIK/System/BasedexClassLoader; AsedexClassloader 'Appears in/System/framework/core-libart.jar) Solution: The error is caused by Multidex's correct initialization.The solution is shown below: 1. Ensure that the application's built.gradle file is introduced. The following dependencies are introduced: implementation 'androidx.multidex:multidex:2.0.1' 2. Multidex initialization in the Application class of the application: import android.content.Context; import androidx.multidex.MultiDex; public class MyApplication extends Application { @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); } } 3. Make sure that in AndroidManifest.xml files, the Application class is specified as myapplication or custom Application class: <application android:name=".MyApplication" ... </application> 二、问题:java.lang.ClassNotFoundException: Didn't find class "android.support.multidex.MultiDexApplication" Error details: java.lang.classnotFoundexception: Didn'T to find class "android.support.multidex.multidexApplic Solution: When using Multidex in AndroidX, no need to inherit Android.Support.multidex.multidexApplication, but should inherit AndroidX.Multides.multidexApplication.The solution is shown below: 1. Multidex initialization in the Application class of the application, and inherit AndroidX.multidex.multidexApplication: import android.content.Context; import androidx.multidex.MultiDex; import androidx.multidex.MultiDexApplication; public class MyApplication extends MultiDexApplication { @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); } } 2. Make sure that in AndroidManifest.xml files, the Application class is specified as MyApplication or custom Application class: <application android:name=".MyApplication" ... </application> 三、问题:java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/multidex/MultiDexApplication; Error details: java.lang.noclassdeffounderror: Failed Resolution of: Landroid/Support/Multidex/MultidexApplication; Solution: The error is due to an error that has not been updated to AndroidX.The solution is shown below: 1. Ensure that the application's built.gradle file is introduced. The following dependencies are introduced: implementation 'androidx.multidex:multidex:2.0.1' 2. Multidex initialization in the Application class of the application, and inherits from Androidx.multidex.multidexApplication: import android.content.Context; import androidx.multidex.MultiDex; import androidx.multidex.MultiDexApplication; public class MyApplication extends MultiDexApplication { @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); } } 3. Make sure that in AndroidManifest.xml files, the Application class is specified as myapplication or custom Application class: <application android:name=".MyApplication" ... </application> in conclusion: This article introduces the common problem solving methods in the Java library using the Multidex framework.Through the correct introduction of dependencies and performed the necessary configuration, the "DEX method limit" error can be solved and the application supports more than 65,536 methods.