Gradle 'Build Script error' occurs when I attempt to use testCompile in dependencies

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.


I stumbled upon this post a year later. I was having this problem because I inherited an older project that was using an out-of-date Gradle build tools setting in the Gradle build file. I fixed this problem by updating Gradle build tools, which you need to do apparently by incrementing the version number in the Gradle build file:

dependencies {
    classpath 'com.android.tools.build:gradle:1.X.X'
}

where X.X is the latest gradle build tools version number. Right now I'm using Android Studio v1.2 and I've got my build tools version number set to:

dependencies {
    classpath 'com.android.tools.build:gradle:1.2.2'
}

I came across this problem when I was trying to implement unit tests, which are now built-in to Android Studio apparently.

Hope this helps someone with the same problem.


I got this "method not found 'testcompile()'" error also. The problem was I had testCompile 'junit:junit:4.12' in my project build.gradle file and not in by app build.gradle file. How could I have known it was in the wrong file? The project file only states "NOTE: Do not place your application dependencies here; they belong in the individual module build.gradle files". Such a simple answer no wonder I couldn't find it.