简体   繁体   English

如何使用android gradle plugin实验0.1.0添加测试依赖项

[英]how to add test dependency with android gradle plugin experimental 0.1.0

I followed this guide to build an ndk hybrid project on Android Studio 1.3.0 RC1 with gradle-experimental:0.1.0 . 我按照指南在Android Studio 1.3.0 RC1上使用gradle-experimental:0.1.0构建了一个ndk混合项目。

Everything is OK, but if I try to add test library dependency, I found the method androidTestCompile is not supported any more. 一切都还可以,但如果我尝试添加测试库依赖项,我发现不再支持androidTestCompile方法了。 Like this: 像这样:

错误:找不到DSL方法

And testCompile also cause the same error. testCompile也会导致同样的错误。

The offical guide doesn't talk about this. 官方指南没有谈到这一点。 So, how can I add add test dependency gradle-experimental Or this version do not supports this function? 那么,我该如何添加添加测试依赖性gradle-experimental或者这个版本不支持这个功能呢?

This is my build.gradle(project): 这是我的build.gradle(项目):

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle-experimental:0.1.0'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

This is build.gradle(moudle): 这是build.gradle(moudle):

apply plugin: 'com.android.model.application'

model {
    android {
        compileSdkVersion = 22
        buildToolsVersion = "23.0.0 rc3"

        defaultConfig.with {
            applicationId = "co.yishun.onemoment.app"
            minSdkVersion.apiLevel = 15
            targetSdkVersion.apiLevel = 22
            versionCode = 5
            versionName = "2.0 canary"
            testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
        }
    }

    android.buildTypes {
        release {
            isMinifyEnabled = true
            proguardFiles += file('proguard-rules.pro')
        }
    }

    android.productFlavors {
        create("flavor1") {
            applicationId = 'com.app'
        }
    }

    android.ndk {
        moduleName = "c_test"
    }
}

dependencies {


    androidTestCompile 'com.android.support.test:runner:0.3'
    // Set this dependency to use JUnit 4 rules
    androidTestCompile 'com.android.support.test:rules:0.3'
    // Set this dependency to build and run Espresso tests
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'


    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:support-annotations:22.2.0'
    compile 'com.android.support:support-v4:22.2.0'
 }

You need to ensure that you are using Gradle 2.5. 您需要确保使用Gradle 2.5。 Under File > Project Structure , navigate to Project and set the "Gradle version" to 2.5. 在“ File > Project Structure ,导航到“ Project并将“Gradle版本”设置为2.5。 Under File > Settings , navigate to Build, Execution, Deployment > Build Tools > Gradle and make sure that "Use default Gradle wrapper (recommended)" is checked. File > Settings ,导航到Build, Execution, Deployment > Build Tools > Gradle ,并确保选中“Use default Gradle wrapper(recommended)”。 Also edit the Gradle wrapper by editing your project's gradle/wrapper/gradle-wrapper.properties file. 还可以通过编辑项目的gradle/wrapper/gradle-wrapper.properties文件来编辑Gradle包装gradle/wrapper/gradle-wrapper.properties Mine looks like this: 我看起来像这样:

#Mon Jul 13 17:55:42 EDT 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip

I did these steps in the above order, but after thinking about it when writing this, perhaps it would be best to reverse the order. 我按照上面的顺序做了这些步骤,但是在写这篇文章之后想到它,也许最好颠倒顺序。 I found that I needed to completely exit Android Studio and restart it before all the changes were recognized. 我发现在完成所有更改后,我需要完全退出Android Studio并重新启动它。 Perhaps something was cached somewhere, or perhaps this was an artifact of the order in which I did things. 也许某些东西被缓存在某个地方,或者这可能是我做事的顺序的一件神器。

Also, see this thread for a little more info about setting the Gradle version. 另外,请参阅此主题以获取有关设置Gradle版本的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM