Skip to main content

How to solve Multidexing problem in Android

            Steps to remove multidexing Problem in Android

What is multidex file and why we need for the APK file?
Android application (APK) files contain executable bytecode files in the form of Dalvik Executable (DEX) files, which contain the compiled code used to run your app. The Dalvik Executable specification limits the total number of methods that can be referenced within a single DEX file to 65,536, including Android framework methods, library methods, and methods in your own code. Getting past this limit requires that you configure your app build process to generate more than one DEX file, known as a multidex configuration.
How to configure our application for multidex?

1. Add  dependency in your app build.gradle(Module:app) and Click on  Sync

 If your API Level is 20 or less than 20 you need  to add support library

    dependencies {
        compile 'com.android.support:multidex:1.0.1'       
 }

  But If your API Level is 21 or more than 21 you do not need  to add support library

2. Insert this line of code in your  build.gradle(Module level) file 

       android {
        defaultConfig {
        minSdkVersion 21      
        targetSdkVersion 26       
        multiDexEnabled true        
               }
           }
3.Then you add this line in  Manifest file
    android:name="android.support.multidex.MultiDexApplication"
 Example:
  <application
    android:allowBackup="true"  
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name"  
    android:supportsRtl="true"  
    android:theme="@style/AppTheme"  
    android:name="android.support.multidex.MultiDexApplication">
4. Create a java file and extends MultiDexApplication in it and install mutidex in it
Example:
public class Myapplication extends MultiDexApplication {
    @Override    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
5.  Click on Sync project

Comments