问题描述
我的 gradle 文件中有两种风味:风味 1 和风味 2.除了构建类型,他们还创建了以下构建变体:
I have two flavors in my gradle file: flavor1 and flavor2. Along with the build types, they create the following build variants:
flavor1-debug
flavor1-release
flavor2-debug
flavor2-debug
假设我想为每个变体设置不同的可绘制对象,我应该把它放在哪里?
Assuming I want to have a different drawable for each variant, where should I put it?
我的文件夹结构是
src
|__ main
|__ flavor1
|__ flavor2
|__ debug
|__ release
我知道,根据 这个那个
所有资源(Android res 和 assets)都使用覆盖优先级其中 Build Type 覆盖 Product Flavor,Product Flavor 覆盖主源集.
这意味着如果我将它放在 Build Type 文件夹中,那么调试变体将具有相同的 debug drawable,而发布变体将具有相同的 release drawable.
This means however that if I put it in the Build Type folder, then the debug variants will have the same debug drawable and the release variants will have the same release drawable.
我想我可以从一开始就创造出更具体的口味,例如flavor1release、flavor1debug、flavor2release、flavor2debug,但我最终会得到 8 个变体.我可能无法根据 this 构建某些构建类型,但这似乎不是很干净.
I guess I could create more specific flavors from the beginning, e.g. flavor1release, flavor1debug, flavor2release, flavor2debug, but I would end up with 8 variants. I could probably not build some of the build types according to this, but that doesn't seem very clean.
推荐答案
实际上还有其他可用的源集.你可以这样做:
There are actually additional sourceSets that are available. You can do this:
src
|__ main
|__ flavor1
|__ flavor1Debug
|__ flavor1Release
|__ flavor2
|__ flavor2Debug
|__ flavor2Release
|__ debug
|__ release
我认为它会给你你想要的——在一个风味 + 构建类型文件夹中,你可以在适当的资源子目录中拥有你的特定于变体的资源.
which I think will give you what you want -- inside one of the flavor + build type folders, you can have your variant-specific resource in the appropriate resource subdirectory.
请参阅 http://tools 上的文档.android.com/tech-docs/new-build-system/user-guide#TOC-Sourcesets-and-Dependencies 了解更多信息.
See the docs at http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Sourcesets-and-Dependencies for more information.
这篇关于Gradle中基于构建变体的不同drawable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!