Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

How to Create Multiple APK Files For Android Application?

  • Last Updated : 30 Aug, 2021

In Android, making a single apk compatible with all devices, increases the apk size, as it has resources for every device. Why make our users download apk that contain device-specific useless resources who are having lower memory devices. Now we got the solution i.e. creating multiple apks from the same application or apk for a specific device. Generating the multiple numbers of apks for a single application, by splitting a single apk into multiple apks, where each apk is specific for a particular device. Multiple apk is mainly used to generate specific apks for different screen densities and different CPU architecture.

How Does the apk Size Reduce?

It does not compress the app size by compressing the resources used within the app. It makes new apks by including only the device compatible resources, and by excluding every other resource that is not compatible or unused for the specific device type. For example, if you are creating two apk one for hdpi and another for xdpi, then in the first apk, there will be no xdpi resources and similarly, in the second apk there will be no hdpi resources.

Want a more fast-paced & competitive environment to learn the fundamentals of Android?
Click here to head to a guide uniquely curated by our experts with the aim to make you industry ready in no time!

Step by Step Implementation

Step 1: Open any application in android studio to create multiple apk.

Step 2: Navigate to the app-level Gradle file.



In general, there are six sets of densities-ldpi, mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi for which we can generate screen density specific apk. Now, we will generate apk for all set of densities excluding mdpi and xxxhdpi with a universal apk.

android {

…….

…….

 splits {

     // build multiple apk based on screen density

     density {

         enable true



         // add list of screen densities for which you do not want your gradle to make apk

         exclude “mdpi”, “xxxhdpi”

          // specify list of compatible screen sizes

         compatibleScreens ‘small’, ‘normal’, ‘large’, ‘xlarge’

     }

 }

}

Sync the Gradle file after adding the above code then click build apk. A notification will be popped up at the right-bottom of the android studio in order to see the located apk files. Otherwise, navigate to the location where all your android projects get saved, open your application then go to app > build > outputs > apk > debug.

To generate multiple apks for specific types of abi:



Set of abi armeabi, armeabi-v7a, arm64-v8a, x86, x86_64, mips, mips64 for which we can generate the abi specific apk. Write these blocks of code in your app-level gradle file and click build apk.

android {

splits {

 abi {

   enable true

   reset()

   include “x86”, “mips”

   universalApk false

 }

}

}

  • reset: To clear all the default list of screen densities (use only if you are using an include).
  • include: You must add reset to your code in order to use include, add a list of densities that you want your gradle to make apk for.

For abi, universalApk is false by default, you need to set it to true to generate Universal Apk.

To generate combined apk for screen density and cpu architecture:

Write these blocks of code in your app-level Gradle file and click build apk.

android {

…..

 splits {

     density {



         enable true

         reset()

         include “mdpi”, “xhdpi”

     }

     abi {

         enable true

         reset()

         include “mips64”, “mips”

     }

This block of code will generate four combined apk for mdpi-mips64, mdpi-mips, xhdpi-mips64, and xhdpi-mips.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!