找不到方法compile()Google GMS

时间:2018-08-24 15:42:29

标签: android kotlin

我正在尝试导入Google Play服务构想,但出现此错误:

  

在类型org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler类型的对象上找不到参数[com.google.android.gms:play-services-vision:15.0.2]的方法compile()

构建gradle是:

// Top-level build file where you can add configuration options common 
to all sub-projects/modules.

buildscript {
  ext.kotlin_version = '1.2.51'
  repositories {
    google()
    jcenter()
    maven {
        url "https://maven.google.com"
    }
 }
dependencies {
    classpath 'com.android.tools.build:gradle:3.1.0'
    classpath "org.jetbrains.kotlin:kotlin-gradle- 
     plugin:$kotlin_version"
    classpath 'com.google.gms:google-services:15.0.2'
    compile 'com.google.android.gms:play-services-vision:15.0.2'

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

allprojects {
 repositories {
    google()
    jcenter()
    maven {
        url "https://maven.google.com"
    }
  }
 }

 task clean(type: Delete) {
   delete rootProject.buildDir
 }

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:1)

请勿将您的应用程序依赖项放在顶层build.gradle中,而应使用模块级别app/build.gradle来定义您的应用程序依赖项。

从最高级别build.gradle删除此行,并将其移至应用程序级别build.gradle

 compile 'com.google.android.gms:play-services-vision:15.0.2'  

希望它能解决您的问题。