In this post, we will see the ways of detecting memory leaks in Android and…
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.
1 2 3 4 5 6 7 8 9 |
android { splits { density { enable true exclude "ldpi" compatibleScreens 'small', 'normal', 'large', 'xlarge' } } } |
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.
1 2 |
reset() include "ldpi", "xxhdpi" |
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.
1 2 3 4 5 6 7 8 |
android { splits { abi { enable true universalApk true } } } |
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,
1 2 3 4 5 6 7 8 9 10 |
android { splits { abi { enable true reset() include "x86", "armeabi" universalApk false } } } |
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
android { splits { density { enable true reset() include "mdpi", "hdpi", "xhdpi" } abi { enable true reset() include "mips64", "mips", "x86" } } } |
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
- Each Apk should have a distinct version code.
- The package name should be identical.
- The method of applying distinct version codes is simple.
Add this to app level gradle file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
ext.densityCodes = ['mdpi': 1, 'hdpi': 2, 'xhdpi': 3] import com.android.build.OutputFile android { android.applicationVariants.all { variant - > variant.outputs.each { output - > def baseDensityVersionCode = project.ext.densityCodes.get(output.getFilter(OutputFile.DENSITY)) if (baseDensityVersionCode != null) { output.versionCodeOverride = baseDensityVersionCode * 1000 + variant.versionCode } } } } |
This Post Has 0 Comments