Вопрос

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.

Это было полезно?

Решение

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.

Другие советы

Create new Directory in res/ with you variant name for debug and release paste drawable image in both dir with same name remove drawable image from main drawable dir. paste and change accordingly below code path , paste below buildtype {} in gradle(app)

sourceSets {
    debug  {
        res.srcDirs = ['src/main/res/debug']
    }

    release{
        res.srcDirs = ['src/main/res/release']
    }
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top