今天我開始將我們的項目轉換爲使用gradle構建系統。我不能改變項目結構,和我有不同的味道,所以我想知道我怎麼能覆蓋爲「開發」和「刺」的sourceset,因爲這顯然是行不通:Gradle productflavors源代碼集和舊項目結構
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4.2'
}
}
apply plugin: 'android'
android {
compileSdkVersion 17
buildToolsVersion "17"
dependencies {
compile project(':ABS')
compile project(':google-play-services_lib')
compile project(':MergeAdapter')
compile fileTree(dir: 'libs', include: '*.jar')
}
signingConfigs {
release {
storeFile file("myapp.keystore")
storePassword "**********"
keyAlias "**********"
keyPassword "**********"
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aild.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
dev {
java.srcDirs = ['src-dev']
}
prod {
java.srcDirs = ['src-prod']
}
instrumentTest.setRoot('tests')
}
productFlavors {
dev {
packageName "com.myapp.dev"
}
prod {
packageName "com.myapp"
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
這給我下面的錯誤:
Cannot add a AndroidSourceSet with name 'dev' as a AndroidSourceSet with that name already exists.
的事情是,我不能使用新的項目結構,我堅持這一個,所以我怎麼在這裏覆蓋源目錄,以便它包括開發人員版,src-dev和prod版本src-prod(而不是src/main/java和src/dev/java或src/prod/java)
Thx!
編輯:src-prod和src-dev目錄只包含具有用於指向不同環境的常量的類。我將使用資產(dev env的不同圖標)做同樣的工作
android flavors demo http://goo.gl/5NSnEM – nitesh