不同的可绘制的基础上构建变量的摇篮 [英] Different drawable based on build variant in Gradle

查看:117
本文介绍了不同的可绘制的基础上构建变量的摇篮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两种口味在我的摇篮文件:flavor1和flavor2。随着构建类型,它们创建以下版本的变种:

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

据我所知,根据<一href="http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Sourcesets-and-Dependencies"相对=nofollow>这个的是

所有的资源(安卓资源和资产)使用覆盖优先使用   其中,生成类型覆盖了产品的风味,其覆盖   主要sourceSet。

All resources (Android res and assets) are used using overlay priority where the Build Type overrides the Product Flavor, which overrides the main sourceSet.

这意味着但是,如果我把它的生成类型文件夹,然后调试变体将具有相同的调试绘制和发布变种都会有相同的版本绘制。

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变种。根据我可能不是建一些构建类型,但是这似乎并没有很干净。

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.

推荐答案

其实有更多的sourceSets可用。你可以这样做:

There are actually additional sourceSets that are available. You can do this:

src
 |__ main
 |__ flavor1
 |__ flavor1Debug
 |__ flavor1Release
 |__ flavor2
 |__ flavor2Debug
 |__ flavor2Release
 |__ debug
 |__ release

我认为会给你你想要的东西 - 里面的味道1 +生成类型的文件夹,你可以在适当的资源子目录中的变体,特定资源

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.

请参阅该文档的<一个href="http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Sourcesets-and-Dependencies" rel="nofollow">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.

这篇关于不同的可绘制的基础上构建变量的摇篮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆