android-studio - Gradle同步失败:找不到参数[com.google.android.gms:play-services-ads:18.2.0]的方法Implementation()

标签 android-studio gradle build.gradle

我的项目中出现以下错误:
11:28 Gradle同步失败:在类型为org.gradle.api.internal.artifacts.dsl的对象上找不到参数[com.google.android.gms:play-services-ads:18.2.0]的方法Implementation() .dependencies.DefaultDependencyHandler。 (10秒801毫秒)

这是build.gradle文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.flixarts.ar.*"
        minSdkVersion 14
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation 'android.arch.lifecycle:extensions:1.1.1'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:recyclerview-v7:27.2.1'
    implementation 'com.android.support:design:27.2.1'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.google.android.gms:play-services-ads:17.2.0'
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.android.support:multidex:1.0.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'com.google.android.gms:play-services-ads:18.2.0'
}

最佳答案

您是否将 gradle版本3.x 或更高版本用作您的gradle版本,并将 4.x 作为您的 gradle-plugin

项目级gradle文件:

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

包装器属性中的Gradle插件distributionUrl配置:
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip

或类(class)的最新版本

https://developer.android.com/studio/releases/gradle-plugin

注意

您在build.gradle中两次使用了有问题的插件:
implementation 'com.google.android.gms:play-services-ads:17.2.0'

implementation 'com.google.android.gms:play-services-ads:18.2.0'

关于android-studio - Gradle同步失败:找不到参数[com.google.android.gms:play-services-ads:18.2.0]的方法Implementation(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57996540/

相关文章:

android - 在根项目中找不到任务 'publishApkRelease'

android - 错误 :duplicate files during packaging of APK

android - 我已经安装了 Android Studio,我的 gradle 正在下载最近 3 小时的文件

macos - Mac 内核崩溃,现在 Android Studio 项目将无法运行

android - 无法在 Android Studio 项目中编译任何外部库

heroku - gradle buildscripts和Heroku

gradle - 使用gradle构建分发zip文件后,如何复制?

Gradle 不运行 TestNG 测试,即使使用 test.useTestNG()

java - Gradle Zip:保留目录结构

android - 如何在 Android Studio Bumblebee 中添加项目级依赖类路径