根据构建风格引用不同的资产 [英] Reference different assets based on build flavor
问题描述
我能够在debug
版本上获得正确的api_key.txt
,因为那是buildType
.但是,我无法在productFlavor amazon
上使用它.
I am able to get the correct api_key.txt
on debug
builds because that is a buildType
. However I am unable to get this working with the productFlavor amazon
.
我尝试在已编译的build.gradle
文件中执行此操作,但实际上在运行时它不会引用正确的文件:
I’ve tried doing this in my build.gradle
file which compiles but it will not actually reference the correct file at run time:
sourceSets {
amazon {
assets.srcDirs = ['app/src/amazon/assets']
}
这是我的文件夹结构:
当我的商品口味为amazon
时,如何在amazon/assets
文件夹中引用api_key.txt
?
How can I reference api_key.txt
in the amazon/assets
folder when my product flavor is amazon
?
非常感谢所有帮助,谢谢.
All help is greatly appreciated, thank you.
推荐答案
基于此 https ://developer.android.com/studio/build/build-variants 文档,您需要这种类型的应用程序层次结构.
从所有构建版本中删除assets.srcDirs
,您可以尝试使用这种结构.
Based on this https://developer.android.com/studio/build/build-variants document you want this type of hierarchy structure of your application.
Remove assets.srcDirs
from all build flavours and you can try with this kind of structure.
buildTypes {
release {
// ... the usual stuff here
}
releaseAlt {
// .. the usual stuff here too like signing config etc...
}
}
文件层次结构,您应该像这样:
file hierarchy You should have like :
project/
- app/
- src/
- main/
- assets/
- logo.png // Generic assets go here
- java/
- res/
- ...
- flavor1/
- assets/
- logo.png // Specific assets for all the flavor1 Variants
- release/
- assets/
- logo.png // Specific assets for all the releaseAlt Variants.
- flavor1Release/
- assets/
- logo.png // very specific assets for the flavor1ReleaseAlt Variant
- SDK/
这篇关于根据构建风格引用不同的资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!