Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle Android Could not find method testPackage()

I have our project building using Gradle. I am now trying to add our tests to the build. I am not totally sure how this works, or what the actuall syntax to use would be.

Here is the build script for a test application I have been trying to get working. My tests are in the src/instrumentTest/java directory.

buildscript {
    repositories {
        maven { url 'http://repo1.maven.org/maven2' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.4'
    }
}
apply plugin: 'android'

dependencies {
    compile files('libs/android-support-v4.jar')
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 16
        testPackage "com.example.myapplication.test"
        testInstrumentationRunner "android.test.InstrumentationTestRunner"
    }
}

When I do a build I get the following error.

FAILURE: Build failed with an exception.

  • Where: Build file '/Users/kbrown/AndroidStudioProjects/MyApplicationProject/MyApplication/build.gradle' line: 22

  • What went wrong: A problem occurred evaluating project ':MyApplication'.

    Could not find method testPackage() for arguments [com.example.myapplication.test] on ProductFlavorDsl_Decorated{name=main, minSdkVersion=8, targetSdkVersion=16, renderscriptTargetApi=-1, versionCode=-1, versionName=null, packageName=null, testPackageName=null, testInstrumentationRunner=null, signingConfig=null}.

like image 228
user2449336 Avatar asked Nov 29 '22 15:11

user2449336


2 Answers

Various attribute names have been changed in Gradle version 1.0

The 'testPackageName' is also replace by 'testApplicationId'

You can check more at Migrating Gradle Projects to version 1.0.0

like image 94
Babasaheb Avatar answered Dec 04 '22 19:12

Babasaheb


The property name to set the package name of the test app is "testPackageName", not "testPackage".

Note that you don't have to provide this, it gets computed automatically based on the name of the tested app by default.

Same thing with the instrumentation runner class, setting it to the default runner has no effect.

like image 29
Xavier Ducrohet Avatar answered Dec 04 '22 18:12

Xavier Ducrohet