简体   繁体   English

每种产品风味不同的 android 资产包

[英]Different android asset pack for each product flavor

I want different product flavors of an android app to have their own asset packs (or possibly none at all).我希望 android 应用程序的不同产品风格拥有自己的资产包(或者可能根本没有)。 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 .但这只是使用所有口味遇到的最后一行,因此所有口味都包含pack2 Any suggestions?有什么建议么?

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.编辑:我找到了适合我需要的解决方案(我想它并不优雅但它有效),也许你也可以使用这个@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).因为我们使用脚本构建应用程序并且我们为每个构建变体调用构建命令,所以我决定使用 Gradle 命令行参数来控制资产是否应该包含在 aab 中(您应该能够轻松修改它以控制应该包含哪些资产) . Then in build.gradle of app module I have a check:然后在应用程序模块的build.gradle中,我进行了检查:

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

and to build aab with assets I invoke command ./gradlew:app:bundle[Variant] -PincludeAssets并使用资产构建 aab,我调用命令./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.到目前为止,我的发现是资产文件总是包含在生成的 aab 文件中。 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 .如果您想控制安装在设备上时哪些风格会下载文件,您必须使用install-time以外的交付类型。 I'll give on-demand a try and update topic if this works.如果可行,我将on-demand尝试并更新主题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM