Updated 22 September 2023
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?
If ourminSdkVersion
is set to 21 or higher, all we need to do is set multiDexEnabled
to true
in our module-level build.gradle
file, as shown here:
1 2 3 4 5 6 7 8 9 |
android { defaultConfig { ... minSdkVersion 21 targetSdkVersion 26 multiDexEnabled true } ... } |
however if our min Sdk Version is less than 21 then we need to following two steps to configure multidex.
step 1:- Modify the module-level build.gradle
file to enable multidex and add the multidex library as a dependency, as shown here:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
android { defaultConfig { ... minSdkVersion 15 targetSdkVersion 26 multiDexEnabled true } ... } dependencies { compile 'com.android.support:multidex:1.0.1' } |
step 2:- Depending on whether we override the Application
class, perform one of the following:
android:name
in the <application>
tag as follows:
1 2 3 4 5 6 7 8 |
<?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> |
Application
class, change it to extend MultiDexApplication
(if possible) as follows:
1 |
public class MyApplication extends MultiDexApplication { ... } |
Application
class but it’s not possible to change the base class, then we can instead override theattachBaseContext()
method and call MultiDex.install(this)
to enable multidex:
1 2 3 4 5 6 7 |
public class MyApplication extends SomeOtherApplication { @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); } } |
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.