Gradle的新手,尝试创建构建变体。我刚刚将一个productFlavor添加到gradle文件中,我得到了这个奇怪的错误
$ gradle tasks
Creating properties on demand (a.k.a. dynamic properties) has been deprecated and is scheduled to be removed in Gradle 2.0. Please read http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html for information on the replacement for dynamic properties.
Deprecated dynamic property: "srcDirs" on "source set aild", value: "[src]".
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'SegmentIO'.
> Cannot add task ':assembleTest' as a task with that name already exists.
这是我的完整build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}
apply plugin: 'android'
dependencies {
compile files('libs/android-support-v4.jar')
}
android {
buildToolsVersion "19.0.1"
compileSdkVersion 17
productFlavors {
test {
}
prod {
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src', 'bundled-src']
resources.srcDirs = ['src']
aild.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
}
// test.assets.srcDirs = ['$java-project-root/assets/test']
// prod.assets.srcDirs = ['$java-project-root/assets/test']
instrumentTest.setRoot('tests')
}
dependencies {
compile fileTree(dir: './libs', include: 'Amplitude.jar')
}
}
答案 0 :(得分:3)
我看到两个问题:
Deprecated dynamic property: "srcDirs" on "source set aild", value: "[src]".
是因为您在构建文件中拼错了aild.srcDirs
- 它应该是aidl.srcDirs
。
> Cannot add task ':assembleTest' as a task with that name already exists.
是因为你正在尝试创建一个名为“test”的风格,但是它正被构建中的其他东西使用并且它正在发生冲突。尝试使用其他名称。
更具体地说,Android插件基于flavor名称创建了许多任务(它也使用构建类型执行此操作)。如果您的名称为“foo”,则 assembleFoo 执行汇编,但仅限于 foo 。已经有一个 assembleTest 任务,所以当它试图为你制作一个时,它会发生碰撞。