已更新至1.12摇篮,摇篮插件机器人工作室0.10。
Updated to gradle 1.12, gradle plugin for android studio 0.10.
我的项目结构如下:
3rdParty文件
3rdparty 图形 图标集 IconsetBase (Android的库) Iconset1 (Android的库) Iconset2 (Android的库) Graphics Iconsets IconsetBase (android-library) Iconset1 (android-library) Iconset2 (android-library)
MainProject
MainProject
在SRC 主要(主体工程) flavor1 flavor2 ... src main (main project) flavor1 flavor2 ...如何获得IconsetBase + Iconset1的资源文件夹的内容将合并到flavor1和IconsetBase + Iconset2到flavor2?
How to get the res folder contents of IconsetBase + Iconset1 to be merged into flavor1 and IconsetBase + Iconset2 into flavor2?
在升级到新的摇篮这一工作作为库(IconsetBase,Iconset1和Iconset2)有相同的包名称主要
Before upgrading to new gradle this worked as the libraries (IconsetBase, Iconset1 and Iconset2) had the same package name as main
下面是我在主项目build.gradle:
Here is my build.gradle of the main project:
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 {
dependencies { compile project(':3rdparty:Graphics:Iconsets:Iconset1') }
res { srcDir 'flavor1' }
resources { srcDir 'flavor1' }
}
android.sourceSets.flavor2 {
dependencies { compile project(':3rdparty:Graphics:Iconsets:Iconset2') }
res { srcDir 'flavor2' }
resources { srcDir 'flavor2' }
}
}
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'
}
=编辑=
=EDIT=
进一步说明:
我追求的是合并从其他位置动态资源。
What I seek is to merge resources from another location dynamically.
背景:flavor1有设定图像ICON1和图标2基地的图标,flavor2有基地图标集和ICON1和图标2还,但图标是每个图标集不同。否则,我就必须有ICON1,图标2等每味多次,并在更新/这些图标的变化必须为每一种滋味现有的做(我有超过20个)
Background: flavor1 has base icon set with images icon1 and icon2, flavor2 has base iconset and icon1 and icon2 also, but the icons are different per icon set. Otherwise I would have to have icon1, icon2 etc. per flavor many times, and on updates /changes of those icons It must be done for every flavor existing (I have more than 20)
难道这是一些自定义任务,实现了无库?
Could this be achieved with some custom task without libraries?
您可以通过味道定义一个特定的依赖关系:
You can define a specific dependency by flavor :
productFlavors {
flavor1 {
...
dependencies {
flavor1Compile project(':iconSet1')
}
}
flavor2 {
...
dependencies {
flavor2Compile project(':iconSet2')
}
}
}
在您构建的依赖都在SourceSets,这就是错误的。
In your build the dependencies are in the SourceSets and that's wrong.
修改
好吧,我希望我更好地了解你现在的目标。你可以做的就是定义每个味道多个资源目录:
Ok, I hope I better understand your goal now. What you can do is defining multiple resource directory for each flavor :
android {
sourceSets {
flavor1 {
res.srcDirs = ['flavor1','../3rdparty/Graphics/Iconsets/Iconset1/res']
}
flavor2 {
res.srcDirs = ['flavor2','../3rdparty/Graphics/Iconsets/Iconset2/res']
}
}
}