How to convert multiple apk files into a unified bundle

Viewed 753

My Android app uses a custom native library (written in C++) that I compile for each of the architectures armeabi-v7a, arm64-v8a, x86 and x86_64. The earliest version of Android that supports 64-bit native libraries (arm64-v8a / x86_64) is API level 21 but with the 32-bit native libraries (armeabi-v7a / x86) I'm able to support devices down to Android API level 16.

Due to those differing API levels and because the compiled libraries get quite big I create a specific apk file for each of those architectures. So, eventually I have 4 different apk files which enables my app to run on pretty much every Android device down to API level 16. That approach works and is documented here. My build.gradle file that builds those apk files looks as follows:

android
{
  ...

  defaultConfig
  {
    minSdkVersion 16
    targetSdkVersion 29
    ...
  }

  flavorDimensions "abi"
  productFlavors
  {
    "ARM7"
    {
      dimension "abi"
      ndk.abiFilters 'armeabi-v7a'
      versionCode 160000 + android.defaultConfig.versionCode
      versionNameSuffix "-arm32"
    }

    "ARM8"
    {
      dimension "abi"
      ndk.abiFilters 'arm64-v8a'
      minSdkVersion 21
      versionCode 210000 + android.defaultConfig.versionCode
      versionNameSuffix "-arm64"
    }

    "x86"
    {
      dimension "abi"
      ndk.abiFilters 'x86'
      versionCode 160000 + android.defaultConfig.versionCode
      versionNameSuffix "-x86"
    }

    "x86-64"
    {
      dimension "abi"
      ndk.abiFilters 'x86_64'
      minSdkVersion 21
      versionCode 210000 + android.defaultConfig.versionCode
      versionNameSuffix "-x64"
    }
  }

  ...
}

Now, Google pushes the new Android Bundle format and the documentation currently states

Important: In the second half of 2021, new apps will be required to publish with the Android App Bundle on Google Play. New apps larger than 150 MB must use either Play Feature Delivery or Play Asset Delivery.

So, at some point I will have to convert my multi-apk approach to that new Android Bundle format but I'm essentially clueless how this is supposed to work. While each of my apk file contains its own manifest with its own version number and minSdkVersion an Android Bundle contains one unified manifest.

How would I be able to create an Android Bundle that eventually has the same effect as my 4 existing apk files?

1 Answers

First of all, there is an easier way of achieving what you already have- splits-on-abi (see https://developer.android.com/studio/build/configure-apk-splits). This method handles the versionCode and so forth for you.

As noted on that page- it's better to use app bundles for this purpose now. App bundles have two main purposes- to minify(/optimize) downloads, and to allow for dynamic modules. The first bit makes it so that Google Play essentially takes your huge app-bundle containing everything, and makes a smaller apk containing only what is needed for the particular device that is asking. It is only this minimal apk that is downloaded to the device.

So, to summarize: You upload one big app bundle to Google Play containing everything for all devices. Google Play then builds minimal apks containing only what is needed, and downloads only those to device. Technically speaking, Google play creates an .apks which is downloaded, this is essentially a zip file with multiple .apk files, following this format: app bundle apks format but that is mostly just an implementation detail you don't need to worry about.

You can simulate and try out how app bundles work (.aab format) with the bundletool (https://github.com/google/bundletool/releases) which according to Google is what Google Play is using to handle app bundle files.

Also, you can drop the flavors. Those will only get in the way now.

Related