问题描述
我正在使用Android Studio,并且在我的应用程序依赖项中,我尝试添加一个testCompile依赖项,如下所示:"> http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html 同步文件时出现错误:我不知道发生了什么,我的根文件夹中的gradle构建文件设置为classpath 'com.android.tools.build:gradle:0.12.+'
,这是最新版本.为什么它不能识别testCompile?我不想将测试依赖项部署到生产中……任何帮助将不胜感激.
I'm working with Android Studio and in my dependencies for my application I attempting to add a testCompile dependency as listed here: http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.htmlWhen I sync my file I get the error: I don't understand what is going on, my gradle build file in my root folder is set to classpath 'com.android.tools.build:gradle:0.12.+'
and that's the most recent version. Why doesn't it recognize testCompile? I don't want to deploy test dependencies to production... Any helps would be appreciated.
这是项目构建文件
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
这是src构建文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 17
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.example.edu.myApp"
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug{
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/scribe-1.3.5.jar')
compile files('libs/json_simple-1.1.jar')
compile 'com.google.android.gms:play-services:5.0.77'
// Can't be higher than 19 if we want to support smaller android versions
compile 'com.android.support:appcompat-v7:19.+'
// You must install or update the Support Repository through the SDK manager to use this dependency.
compile 'com.android.support:support-v4:19.+'
// This Mockito includes all dependancies (great for us)
testCompile "org.mockito:mockito-core:1.9.+"
testCompile 'org.hamcrest:hamcrest-all:1.3'
testCompile 'org.objenesis:objenesis:1.2'
}
推荐答案
您应该使用androidTestCompile
,而不是testCompile
.如果这是由于通过项目结构"对话框修改了依赖关系范围而引起的,则存在一个错误,即它使用错误的语句来建立依赖关系.我已经提交了 https://code.google.com/p/android/issues/detail? id = 74771 .
You should use androidTestCompile
, not testCompile
. If this is due to modifying the dependency scope via the Project Structure dialog, then there's a bug where it uses the wrong statement to set up the dependency. I've filed https://code.google.com/p/android/issues/detail?id=74771 for this.
这篇关于当我尝试在依赖项中使用testCompile时,发生Gradle“生成脚本错误"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!