Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
443 views
in Technique[技术] by (71.8m points)

android - Different drawable based on build variant in Gradle

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?

My folder structure is

src
 |__ main
 |__ flavor1
 |__ flavor2
 |__ debug
 |__ release

I am aware, according to this that

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.

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

See the docs at http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Sourcesets-and-Dependencies for more information.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...