找不到参数 [com.google.android:support-v4:r7] 的方法实现()

Could not find method implementation() for arguments [com.google.android:support-v4:r7]

我是一个总 Android / Java 新手,在下面遇到了一个我想编译的项目:

https://github.com/maxamillion32/Android-Firebase-mapping

它有点旧,也许这就是它给我带来问题的原因。

我下载的 Build Tools 24.0.1 出现的第一个错误。现在我收到以下无法解决的错误:

Caused by: org.gradle.internal.metaobject.AbstractDynamicObject$CustomMessageMissingMethodException: Could not find method implementation() for arguments [com.google.android:support-v4:r7] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

我已经在文件 > 项目结构中检查了我的依赖项并且 com.google.android:support-v4:r7 在那里。

build.gradle(项目)

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

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.3'
        classpath 'com.google.gms:google-services:4.3.3'

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

allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

build.gradle(应用程序)

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

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"
    defaultConfig {
        applicationId "com.mimming.hacks.starter"
        minSdkVersion 19
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE-FIREBASE.txt'
        exclude 'META-INF/NOTICE'
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation 'com.android.support:appcompat-v7:23.4.0'
    implementation 'com.google.android.gms:play-services:9.6.1'
    testImplementation 'junit:junit:4.12'

//    compile 'com.firebase:firebase-client-android:2.5.2+'
    apply plugin: 'com.google.gms.google-services'
    implementation 'com.google.firebase:firebase-database:9.6.1'

}

有什么想法吗? 谢谢!

使用的gradle版本好像是低版本,为了使用implementation gradle版本应该在3

以上
  1. 您应该将 build.gradle 中的依赖项替换为最新版本。
classpath 'com.android.tools.build:gradle:3.6.3'
  1. 此外,您还必须升级 distributionUrl
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip

正如您已经提到的,您已经更新了 buildToolsVersion,这应该可以正常工作,并确保所有依赖项都使用 implementation 而不是 compile,因为编译已被弃用。