Creating multiple Apk files in Android

Android devices have now evolved in different architectures. Different architectures in the sense, various screen densities, various screen resolutions, and various hardware support. It is fine to have a single Apk for one of your application, but imagine it supporting the new market. Yes, it should support all the devices by the way. So to make the Apk supportive to all the devices you might need to add all the resources required for the support, which eventually increases your apk size.

On the other side, it becomes useless for some users to have the resources that were intended for other devices. Also, it is a waste of downloaded data. Now the solution to this is to make the Apk support a specific number of devices and keeping the file size reduced. Say Hi to Multiple Apk.

The idea is nothing but generating a number of Apk’s for the same application, by splitting the Apk into multiple Apk’s, where each supports a set of devices. These Apk’s are aimed to support devices sorting them under screen densities and Processor types.

1. Screen density specific

There are six common screen densities for which Apk’s need to be generated.

– ldpi, mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi

We usually don’t need to create one for ldpi since it is for low density, and it is very rare that one will use such screen sizes in today’s scenario.

 

This block of Gradle will help generate an Apk that support all densities of devices excluding ldpi. If you want the Apk to support ldpi too, simply remove the line exclude “ldpi”.

Let’s see what each of the syntaxes really mean.

density – This means the screen densities of devices such as mdpi, hdpi, etc,. This block allows adding a set of build variants based on screen density.

exclude – If you do not want to generate Apk for a specific density, simply use the exclude syntax to the block.

exclude "ldpi", "mdpi"

reset – reset option clears all the list of screen densities. This will be useful only if you use include and include your own set.

include – As I said above, include option is used to include your own set of densities. You will need to use reset and then use include to include your set alone.

compatibleScreen – You can specify the list of compatible screen sizes. If your Apk should support all the available screen sizes, use

compatibleScreens small, normal, large, xlarge

Someone won’t really need to remove compatibility with his Apk. In some cases, if you don’t want your Apk to support a specific screen resolution, simply remove the same from the compatible screens line.

Universal apk – When this is used to the gradle, it helps generate a universal Apk that is compatible with every device available.

 

General variants of abi are armeabi, armeabi-v7a, arm64-v8a, mips, mips64, x86, x86_64. For abi specific setup, universalApk is set to false by default.

To generate abi specific Apk,

 

Thus if you need to generate Apk that support both the screen density and Processor architecture, you need to write code blocks for both density and abi.

 

This code will generate 9 combined Apk sets for mdpi-mips64, mdpi-mips, mdpi-x86, hdpi-mips64, hdpi-mips, hdpi-x86, xhdpi-mips64, xhdpi-mips. and xhdpi-x86.

 

Rules while uploading multiple Apk to Play Store

  1. Each Apk should have a distinct version code.
  2. The package name should be identical.
  3. The method of applying distinct version codes is simple.

Add this to app level gradle file

Leave a Reply

Your email address will not be published. Required fields are marked *