Different drawable based on build variant in Gradle(Gradle中基于构建变体的不同drawable)
问题描述
我的 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 覆盖主源集.
All resources (Android res and assets) are used using overlay priority where the Build Type overrides the Product Flavor, which overrides the main sourceSet.
这意味着如果我将它放在 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Gradle中基于构建变体的不同drawable
基础教程推荐
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01