Gradle构建找不到方法 [英] Gradle build can't find method

查看:1042
本文介绍了Gradle构建找不到方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注开始Android版开发课程在Pluralsight。我们正准备添加测试。说明说要添加 androidTestCompile'c​​om.android.support.test.espresso:espresso-core:2.2.2' build.gradle file:

I'm following through the Start Developing for Android course in Pluralsight. We're just about to add tests. The instructions say to add add androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2' to the build.gradle file:

// 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文件发生变化时,需要再次同步。当我这样做但我收到以下错误:

After doing this IntelliJ tells me that as the Gradle file has changed, it needs to sync again. When I do it though I get the following error:

错误:

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.1 2.2.2

什么是在这里?

谢谢

推荐答案

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

The dependency should be added to the build.gradle of the app module. In your case you added to the build.gradle of parent project.

这篇关于Gradle构建找不到方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆