Android SDK Product Flavors

Working with multiple aar library files (≥ 1.5)

The THEOplayer library comes in two versions (since version 1.5.0). The minApi16 aar file supports all devices starting with android Jellybean and the minApi21 aar file supports all devices starting with Lollipop.

The easiest way to use the SDK if you want to support the largest possible amount of devices is to use the minApi16 version.

However, the file size of the minApi16 version is about 50MB while the minApi21 is less than 1MB.

For that reason, it is useful to use both in a way that users who have Android Lollipop or higher will have a much smaller APK file. Furthermore, for the pre-Lollipop users, it is possible to reduce the file size by only including the binary files for their target platform (armv7l or x86).

1. Reducing apk file size using product flavors

To do this, first import both libraries as described in the Getting Started section.

Then you need to edit the app's builld.gradle file to use multiple product flavors and choose which aar file to compile per flavor. Using product flavors, you can differentiate based on API level and processor architecture.

The example below shows how your gradle file could look. Notice how the product  flavor names are prefixed to compile in order to achieve selective aar compilation.

When uploading your apk files to the play store (which allows uploading multiple apk files for the same application), you should have the same application id for every flavor but a different version number. The play store will select the compatible apk with the highest version number.

So it is important that the flavor with a higher minimum API level has a higher version number because the one with the lower minimum api level will still be compatible with Lollipop (and higher) devices but should not be chosen for Lollipop (and higher) devices.

Also the x86 product flavor should have a higher version number than the arm flavor because devices with an x86 processor architecture are also able to run arm code.

In our example we have chosen to not use the splits option to differentiate between processor architectures but instead we have filtered for this in the product flavors. In this way, we can specify that for minimum API level 21, there should not be different apk files for different architectures but instead only one file for all architectures.

2. Example build.gradle file

android {
  compileSdkVersion 25
  buildToolsVersion "25.0.2"
  defaultConfig {
      applicationId "com.yourComp.yourApp"
      minSdkVersion 16
      targetSdkVersion 25
      versionCode 1
      versionName "1.0"
  }
  productFlavors {
      minApi16Arm {
          minSdkVersion 16
          ndk {
              abiFilter "armeabi-v7a"
          }
          versionCode Integer.parseInt("161" + android.defaultConfig.versionCode)
      }
      minApi16X86 {
          minSdkVersion 16
          ndk {
              abiFilter "x86"
          }
          versionCode Integer.parseInt("162" + android.defaultConfig.versionCode)
      }
      minApi21 {
          minSdkVersion 21
          versionCode Integer.parseInt("210" + android.defaultConfig.versionCode)
      }
  }
}
dependencies {
  compile fileTree(include: ['*.jar'], dir: 'libs')
  compile 'com.android.support:appcompat-v7:25.3.1'
  compile 'com.google.code.gson:gson:2.8.0'
  compile 'com.android.support:mediarouter-v7:25.3.1'
  compile 'com.google.android.gms:play-services-cast-framework:10.2.1'
  minApi21Compile project(':theoplayer-android-sdkdemo-1.5.0-minApi21-release')
  minApi16ArmCompile project(':theoplayer-android-sdkdemo-1.5.0-minApi16-release')
  minApi16X86Compile project(':theoplayer-android-sdkdemo-1.5.0-minApi16-release')
}

3. Building and Play Store upload

After you have successfully edited the build.gradle file of your app, you should  be able to select the build variant in the left pane under Build Variants to select which flavor is compiled when debugging and building and APK.

When building a signed APK, you can select all the flavors by holding the control button to build them all in the last screen of the signed apk creation wizard.

These apk files can then be uploaded to the play store for the same release of your app.