Different android asset pack for each product flavor

711 views Asked by At

I want different product flavors of an android app to have their own asset packs (or possibly none at all). Tried something like

android {
   productFlavors {
       one {
          assetPacks[":pack1"]
       }
       two {
          assetPacks[":pack2"]
       }
       three {
       }
   }
}

but this just uses the last line encountered for all flavors, so that all of them include pack2. Any suggestions?

1

There are 1 answers

1
Piotr Przywieczerski On

Edit: I have found solution which suits my needs (I guess it's not elegant but it works), maybe you can also use this @KasperPeeters. Because we build applications using script and we invoke build commands per build variant I decided to use Gradle command line param which controls if assets should be included in aab or not (you should be able to easily modify it to control which assets should be included). Then in build.gradle of app module I have a check:

if (project.hasProperty("includeAssets")) { assetPacks = [":<you_asset_name>"] }

and to build aab with assets I invoke command ./gradlew :app:bundle[Variant] -PincludeAssets


I am looking for something similar. My discovery so far is that assets files are always included in generated aab file. If you want to control which flavors will download the file when installed on the device you have to use delivery type other than install-time. I'll give on-demand a try and update topic if this works.