Multiple APK support trong Android.

Tram Ho

Hello everyone, today we will learn together about Multiple APK support in Android.

1. What is Multiple APK support in Android?

Multiple APK support in Android is a feature that allows developers to upload different apk versions, each of which is a complete and independent version of your app, but they share the same app list. on Google Play and must share the same package name and be signed with the same release key (keystore). This feature is useful for cases where your application cannot reach all desired devices with just one APK. When it comes to this, people will probably think of the Android App Bundle when uploading applications to Google Play, with which Google Play will automatically generate and provide the optimal apk for each user device configuration, that makes downloading and updating very smooth for users and the developer, very excellent, but today we will not learn about it but rather Multiple APK support.

2. Why publish multiple apk versions?

There are many reasons for this, but generally, when you publish an app, whether it succeeds or not depends heavily on whether your app provides a good experience for as many devices as possible. well, of course you can do this in an apk file, we often have to do that, but when this becomes too complicated by the alternative resources that make the apk bulge or difficult to technically prevented because Android has too many devices with too many developers participating in customizing everything and this is beyond the capacity of an apk file, then you will have to build many apk files and Google Play will help you distribute to appropriate devices through the support configuration that you declare in each ap file k. This can give you the following specific benefits – and also what Google Play can now support:

  • Supports different OpenGL structure formats with each APK.
  • Support different screen sizes and densities with each APK.
  • Support different device features with each APK.
  • Support different platform versions with each APK.
  • Support different CPU architectures with each APK (such as ARM or x86, when your application uses Android’s NDK).
  • Optimized for special devices, such as those running Android Go.

3. How it works.

With the above great support, we will probably wonder how Google Play will do it, this will be done through the declaration of the tags in each of your apk files such as:

  • Support for various OpenGL structure formats -> Declared based on <supports-gl-texture> tag in Manifest file with structure:

The name attribute is where you define values ​​to identify apk versions such as:

  • Support for different screen sizes and densities -> Declared based on one of the <supports-screens> hoặc <compatible-screens> in the manifest file, you cannot use these two cards at the same time and Google has It is recommended that you only use the <supports-screens> tags. This example happens when you publish an apk file specifically for small screen devices and another version specific to larger screen devices. By default the values ​​in <supports-screens> will always be true if you do not redefine, for example:

or tags.

Of course with each property you will choose true or false as you like. However, in the case of screen sizes, Google recommends that you should not split the apk just because of that and Google also supports multi screens very fully already and you should follow. And why should not use the two tags on the same, because when using both will cause errors when the two components conflict with each other due to errors in declaring, for example.

  • Supports various device features -> Declared based on <uses-feature> tag in Manifest file with structure:

Specific examples such as those required with cameras and bluetooth for example:

By specifying the features that your application requires, you authorize Google Play to make your app available only to users whose devices meet the feature feature requirements of the application, rather than visible to all both users.

  • Optimized for special devices, such as those running Android Go -> This part is simpler. To target Android devices (Go version), your APK needs to declare <used-Feature android: name = "android.hardware.ram.low" android: required = "true"> in the manifest file . And the target api must be at least 26 and the version code must also be higher than the apk version for other devices.
  • Limiting by api level -> This part is quite familiar. You can do this based on your <used-sdk> file manifest file. You can use both android: minSdkVersion and android: maxSdkVersion attributes to specify support for different API levels.
  • Limits according to the architecture of cpu (such as intel chip is different from qualcom for example) -> You can do this through declaration in the build.gradle file of your application, for example:

With this declaration ARMv5 / v6 devices will not be compatible with this apk version, or if you just want to support "x86" then MOVBE or SSE4. devices MOVBE or SSE4. will not be compatible with that apk version. You can also declare multiple types at the same time such as:

With this declaration the device will support 64-bit AArch64 and x86 64bit architectures.

4. Rules for using multiple apk.

Before you publish multiple APKs for your app, you need to understand the following rules:

  • All APKs you publish for the same application must have the same package name and be signed with the same certificate key.
  • Each APK must have a different version code, which is specified by the android: versionCode.
  • Each APK does not exactly match the other APK’s configuration support. That is, each APK must declare a different support for at least one of the supported Google Play filtering properties (listed above). Typically, you will differentiate your APK based on a specific feature (such as supported structural compression formats), and so each APK will declare support for different devices. However, you can publish multiple APKs that overlap a little bit on several declarative characteristics. When two APKs overlap (they support a number of identical device configurations), run in conditions that satisfy both of those apk will get the APK with the higher version code (determined by android: versionCode ).
  • VersionCode for later version must be higher than the previous version, if you set lower you will not be able to conduct application updates.
  • The apk that requires a higher api level corresponds to a higher versionCode declaration.

5. Summary.

Above I briefly introduced about Multiple APK support in Android. However, to be able to do it, I still have to learn more, above I just introduce basic for you to learn more. Thank you for following the article. You can also refer to the source at https://developer.android.com/guide

Share the news now

Source : Viblo