Build Multiple APKs in Android

Posted By : Prince Bhardwaj | 31-Jan-2018

In spite of the fact that we can make one apk to help all our android gadgets yet this may bring about a vast apk because of records expected to help different screen densities.We can reduce size of APK by creating multiple APKs which contains files only for specific screen densities.

Gradle can make seperate APKs which contains code and assets particular to each density.In this blog, we have talked about how to arrange our work to create different APKs.

 

How To Configure Build For Multiple APKs 

 

To configure our build for multiple Apks, we have to add splits block to our module-level bild gradle file. In our splits block, we have to provide a density block which specifies how gradle should generate pre-density APKs or an ABI block that specifies how gradle should generate per ABI APKs. We can also provide both density and ABI blocks, and the build system will create an APK for each density and ABI combination.


Note:In this blog, we have only explained how to configure multiple APKs for screen densities.

 

Configure Multiple APKs For Screen Densities 

 

To create seperate APKs for different screen densities, we need to add density block in our splits block. For this,we have to add list of desired screen densities and compatible screen sizes. The following gradle DSL options are used to configure multiple APKs for screen densities-

enable

If we set this element to true, Gradle creates muptiple APKs based on ensities we have provided.


exclude

Specifies a comma separated list of densities that Gradle should not generate separate APKs for.


reset()

Clears the default list of screen densities.

 

include

Specifies a comma separated list of densities that Gradle should generate separate APKs for.

 

compatibleScreens

Specifies a comma separated list of screen sizes.


Here is an example to generate separate APK for each screen density listed in Range of screen supported except ldpi and xxxhdpi -

 

 

android {
  ...
  splits {

     {

      // Designs different APKs in light of screen density.
      enable true

      // Defines a list of screen densities for which Gradle should not create multiple APKs for.
      exclude "ldpi", "xxxhdpi"

      // Defines the list of compatible screen size settings for the manifest.
      compatibleScreens 'small', 'normal', 'large', 'xlarge'
    }
  }
}

About Author

Author Image
Prince Bhardwaj

Prince Bhardwaj is having Talent as Application Developer, he is an enthusiastic team player in Oodles Technologies.

Request for Proposal

Name is required

Comment is required

Sending message..