首页 > 解决方案 > 找不到方法 compile() google gms

问题描述

我正在尝试导入 google play services vision 但给我这个错误:

在 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
 }

谁能帮我?

标签: androidkotlin

解决方案


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

从此顶层删除此行build.gradle并将其移至 app level build.gradle

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

希望它能解决您的问题。


推荐阅读