当我尝试在依赖项中使用 testCompile 时,发生 Gradle“构建脚本错误”

2024-06-24

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.html http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html When I sync my file I get the error: sync error screenshot 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, not testCompile。如果这是由于通过“项目结构”对话框修改依赖关系范围造成的,则存在一个错误,即它使用错误的语句来设置依赖关系。我已备案https://code.google.com/p/android/issues/detail?id=74771 https://code.google.com/p/android/issues/detail?id=74771为了这。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

当我尝试在依赖项中使用 testCompile 时,发生 Gradle“构建脚本错误” 的相关文章

随机推荐