問題描述
我的 gradle 文件中有兩種風(fēng)味:風(fēng)味 1 和風(fēng)味 2.除了構(gòu)建類型,他們還創(chuàng)建了以下構(gòu)建變體:
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
假設(shè)我想為每個(gè)變體設(shè)置不同的可繪制對(duì)象,我應(yīng)該把它放在哪里?
Assuming I want to have a different drawable for each variant, where should I put it?
我的文件夾結(jié)構(gòu)是
src
|__ main
|__ flavor1
|__ flavor2
|__ debug
|__ release
我知道,根據(jù) 這個(gè)那個(gè)
所有資源(Android res 和 assets)都使用覆蓋優(yōu)先級(jí)其中 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 文件夾中,那么調(diào)試變體將具有相同的 debug drawable,而發(fā)布變體將具有相同的 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.
我想我可以從一開始就創(chuàng)造出更具體的口味,例如flavor1release、flavor1debug、flavor2release、flavor2debug,但我最終會(huì)得到 8 個(gè)變體.我可能無法根據(jù) this 構(gòu)建某些構(gòu)建類型,但這似乎不是很干凈.
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.
推薦答案
實(shí)際上還有其他可用的源集.你可以這樣做:
There are actually additional sourceSets that are available. You can do this:
src
|__ main
|__ flavor1
|__ flavor1Debug
|__ flavor1Release
|__ flavor2
|__ flavor2Debug
|__ flavor2Release
|__ debug
|__ release
我認(rèn)為它會(huì)給你你想要的——在一個(gè)風(fēng)味 + 構(gòu)建類型文件夾中,你可以在適當(dāng)?shù)馁Y源子目錄中擁有你的特定于變體的資源.
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.
請(qǐng)參閱 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.
這篇關(guān)于Gradle中基于構(gòu)建變體的不同drawable的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!