这个问题是对Android gradle library resources in product flavor
的跟进想出了一个奇怪的问题。
正如Android gradle library resources in product flavor中所述,当为每种风格使用多个源集时,对于资源和资源,一切正常,其他目录中的资源都会合并在一起。
问题: flavor值/ strings.xml不会替换主项目中的值/ strings.xml (这是我保留应用程序标签和应用程序图标的地方)。因为这种行为,我的应用程序图标和标题搞砸了(而不是风味)。
我在这里找到了一些东西:http://tools.android.com/tech-docs/new-build-system/resource-merging (标题处理多个资源文件夹)但这并没有帮助我进一步,因为我不明白如何强制这个特定的flavor文件覆盖主项目中的另一个。
==编辑==
我的项目结构和build.gradle(主项目)
项目结构
的3rdParty
- 图形
- 图标集
- IconsetBase
- Iconset1
- Iconset3
MainProject
- SRC
- 主要(主要项目)
- 的 flavor1
- 的 flavor2
- ...
build.gradle(主项目)
buildscript {
repositories {
mavenCentral()
}
dependencies {
repositories {
mavenCentral()
}
classpath 'com.android.tools.build:gradle:0.10.0'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
useOldManifestMerger false
compileSdkVersion 19
buildToolsVersion "19.0.3"
lintOptions {
...
}
sourceSets {
main.java.srcDirs = ['src/main/java']
main.resources.srcDirs = ['src/main/res']
}
signingConfigs {
...
}
buildTypes {
...
}
// Common dependencies
dependencies {
compile project(':3rdparty:Graphics:Iconsets:IconsetBase')
}
defaultConfig {
...
}
productFlavors {
flavor1 { packageName "..."}
flavor2 { packageName "..."}
}
android.sourceSets.flavor1 {
res {
srcDirs = ['flavor1','../3rdparty/Graphics/Iconsets/IconsetBase/src/main/res', '../3rdparty/Graphics/Iconsets/Iconset1/src/main/res']
}
resources {
srcDirs = ['flavor1','../3rdparty/Graphics/Iconsets/IconsetBase/src/main/res', '../3rdparty/Graphics/Iconsets/Iconset1/src/main/res']
}
}
android.sourceSets.flavor2 {
res {
srcDirs = ['flavor2','../3rdparty/Graphics/Iconsets/IconsetBase/src/main/res', '../3rdparty/Graphics/Iconsets/Iconset3/src/main/res']
}
resources {
srcDirs = ['flavor2','../3rdparty/Graphics/Iconsets/IconsetBase/src/main/res', '../3rdparty/Graphics/Iconsets/Iconset3/src/main/res']
}
}
}
dependencies {
compile 'com.android.support:support-v4:19.1.0'
compile 'com.android.support:appcompat-v7:19.1.0'
compile 'com.google.android.gms:play-services:4.3.23'
}
解决
问题出在MainProject.iml
上向RES_FOLDERS_RELATIVE_PATH添加风味路径后,一切正常