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'
}
The testCompile configuration contains the dependencies which are required to compile the tests of our project. This configuration contains the compiled classes of our project and the dependencies added to the compile configuration.
For this, you have to connect your PC to the internet and you have to open your Android studio. After opening your project click on the Sync Project with Gradle files option. This will automatically download the new Gradle files and will fix the issue which is caused by the Gradle files.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With