Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

Everything is OK, but if I try to add test library dependency, I found the method androidTestCompile is not supported any more. Like this:

Error: DSL method not found

And testCompile also cause the same error.

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?

This is my build.gradle(project):

// 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):

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'
 }
like image 494
Carlos Parker Avatar asked Jul 11 '15 08:07

Carlos Parker


1 Answers

You need to ensure that you are using Gradle 2.5. Under File > Project Structure, navigate to Project and set the "Gradle version" to 2.5. Under File > Settings, navigate to Build, Execution, Deployment > Build Tools > Gradle and make sure that "Use default Gradle wrapper (recommended)" is checked. Also edit the Gradle wrapper by editing your project's gradle/wrapper/gradle-wrapper.properties file. 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. 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.

like image 186
Ted Hopp Avatar answered Oct 02 '22 22:10

Ted Hopp