【问题标题】:Gradle Sync failed: Could not find method implementation()Gradle 同步失败:找不到方法实现()
【发布时间】:2018-09-09 07:56:33
【问题描述】:

几个小时以来一直在尝试解决此错误...无法解决。我是 Android Studio 的新手

我的项目级build.gradle文件如下

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

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

    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'
        classpath 'com.google.gms:google-services:4.0.1'

    }
}

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

而我的app build.gradle文件如下

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 18
    buildToolsVersion "26.0.1"

    defaultConfig {
        applicationId "com.amazonaws.androidtest"
        minSdkVersion 8
        targetSdkVersion 18
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

    aaptOptions {
        cruncherEnabled = false
    }

    dependencies {
        implementation 'com.google.firebase:firebase-core:16.0.1'

    }
}

apply plugin: 'com.google.gms.google-services'

尝试同步时出现以下错误

Gradle sync failed: Could not find method implementation() for arguments [com.google.firebase:firebase-core:16.0.1] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

我使用的是 Android Studio 2.3

尝试将 Gradle 升级到版本 4,但这需要 Android Studio 3。目前无法安装 Android Studio 3。

还添加了一些答案建议的maven url。还是不行。

还有其他办法解决吗?

【问题讨论】:

    标签: android-studio gradle


    【解决方案1】:

    使用 build-tools 3.1.4,它应该是已知的(阅读下文):

    classpath "com.android.tools.build:gradle:3.1.4"
    

    但如果您无法更新 Android Studio,请使用 compile 而不是 implementation

    compile "com.google.firebase:firebase-core:16.0.3"
    

    【讨论】:

    • 软件开发是一个如此奇怪的领域...我花了几个小时寻找解决方案,解决方案只是更改 1 个单词(实现 -> 编译)...谢谢
    猜你喜欢
    • 2019-07-26
    • 2016-10-05
    • 2019-04-02
    • 1970-01-01
    • 1970-01-01
    • 2020-09-16
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    相关资源
    最近更新 更多