当我尝试在依赖关系使用testCompile摇篮“构建脚本错误”发生 [英] Gradle 'Build Script error' occurs when I attempt to use testCompile in dependancies

查看:383
本文介绍了当我尝试在依赖关系使用testCompile摇篮“构建脚本错误”发生的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与Android的工作室,在我的依赖关系我的应用程序试图添加一个testCompile依赖此处所列的工作:<一href=\"http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html\">http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
当我同步我的文件,我得到的错误:
我不明白是怎么回事,在我的根文件夹的gradle我的构建文件设置为类路径com.android.tools.build:gradle:0.12 +,这就是最新的版本。为什么它不承认testCompile?我不想依赖测试部署到生产...任何帮助将AP preciated。

编辑:这里是项目生成文件

  buildscript {
    库{
        jcenter()
    }
    依赖{
        类路径'com.android.tools.build:gradle:0.12.+
        //注意:不要在这里把你的应用程序依赖关系;他们属于
        //在单个模块的build.gradle文件
    }
}
allprojects {
    库{
        jcenter()
    }
}

和这里的SRC构建文件:

 应用插件:'com.android.application
安卓{
    compileSdkVersion 17
    buildToolsVersion20.0.0
    defaultConfig {
        的applicationIDcom.example.edu.myApp
        14的minSdkVersion
        targetSdkVersion 19
        版本code 1
        的versionName1.0
    }
    buildTypes {
        发布 {
            runProguard假
            proguardFiles getDefaultProguardFile('proguard的-android.txt'),'proguard-rules.pro
        }
        调试{
            runProguard假
            proguardFiles getDefaultProguardFile('proguard的-android.txt'),'proguard-rules.pro
        }
    }
}
依赖{
    编译文件树(导演:'库',包括:['的* .jar'])
    编译文件(库/划线1.3.5.jar')
    编译文件(库/ json_simple-1.1.jar')
    编译com.google.android.gms:播放服务:5.0.77
    //不能高于19,如果我们想支持小的Andr​​oid版本
    编译com.android.support:appcompat-v7:19.+
    //您必须安装或通过SDK管理器更新支持信息库使用这种依赖性。
    编译com.android.support:support-v4:19.+
    //这个包含的Mockito所有的依赖关系(对我们很有用处)
    testCompileorg.mockito:的Mockito芯:1.9 +
    testCompile'org.hamcrest:hamcrest全:1.3'
    testCompile'org.objenesis:objenesis:1.2
}


解决方案

您应该使用 androidTestCompile ,而不是 testCompile 。如果这是由于通过项目结构对话框修改依赖范围,再有就是它使用了错误的语句来建立依赖关系的错误。我提起<一个href=\"https://$c$c.google.com/p/android/issues/detail?id=74771\">https://$c$c.google.com/p/android/issues/detail?id=74771这一点。

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 When 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.

EDIT: Here is the project build file

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()
    }
}

and here is the src build file:

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'
}

解决方案

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摇篮“构建脚本错误”发生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆