我很感激任何对此的帮助,因为我是一个noobie w / gradle。我有一个包含多个buildTypes的构建脚本,但是其中一个构建脚本的设置会覆盖其他构建脚本。
这是我的build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4.2'
}
}
apply plugin: 'android'
dependencies {
compile project(':facebook-android-sdk-3.0.1:facebook')
compile project(':google-play-services_lib')
compile project(':nineoldandroids')
compile project(':SlidingMenu-master:library')
compile project(':ViewPagerIndicator')
compile project(':volley')
compile project(':windowed-seek-bar')
compile files('compile-libs/androidannotations-2.7.1.jar', 'libs/Flurry_3.2.1.jar', 'libs/google-play-services.jar', 'libs/gson-2.2.4.jar', 'libs/picasso-1.1.1.jar', 'libs/crittercism_v3_0_11_sdkonly.jar', 'libs/gcm.jar', 'libs/apphance-library.jar')
}
android {
buildToolsVersion "17.0"
compileSdkVersion 17
signingConfigs {
debug {
storeFile file('keystores/debug.keystore')
}
release {
storeFile file('keystores/release.keystore')
storePassword "***"
keyAlias "***"
keyPassword "***"
}
}
buildTypes {
debug {
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src', 'normal']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
release {
signingConfig signingConfigs.release
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src', 'normal']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
utest {
debuggable true
signingConfig signingConfigs.debug
sourceSets {
main {
manifest.srcFile 'utest/AndroidManifest.xml'
java.srcDirs = ['src', 'utest']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
}
}
utest的设置会覆盖发布和调试的设置。有谁知道为什么?
答案 0 :(得分:12)
您对源集的使用是错误的。它不在每个构建类型闭包内。他们是自己宣布的:
android {
buildTypes {
debug {
...
}
release {
...
}
utest {
...
}
}
sourceSets {
debug {
...
}
release {
...
}
utest {
...
}
}
}
请注意,构建类型在“主要”源集之上有自己的源集。因此,您不应将所有构建类型sourceset设置为使用'src'。你可以做到
android {
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
utest {
manifest.srcFile 'utest/AndroidManifest.xml'
java.srcDirs = ['utest']
}
}
}
请注意,在这种情况下,utest/AndroidManifest.xml
下的清单将合并到主清单中。