Gradle构建无法找到方法

时间:2016-12-30 15:46:17

标签: java android intellij-idea

我正在通过Pluralsight的Start Developing for Android课程。我们即将添加测试。说明添加androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'文件添加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:2.2.1'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
  }
}

allprojects {
  repositories {
    jcenter()
  }

  dependencies {
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
  }
}

执行此操作后,IntelliJ告诉我,当Gradle文件发生更改时,需要再次同步。当我这样做时,我收到以下错误:

错误:

15:17   Gradle sync failed: Could not find method androidTestCompile() for arguments [com.android.support.test.espresso:espresso-core:2.2.1] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
            Consult IDE log for more details (Help | Show Log)

注意:我尝试了2.2.12.2.2版本。

这里发生了什么?

由于

1 个答案:

答案 0 :(得分:1)

应将依赖项添加到build.gradle模块的app。在您的情况下,您已添加到父项目的build.gradle