How to fix "ERROR: Gradle DSL method not found" on Android Studio 3.3

How to fix "ERROR: Gradle DSL method not found" on Android Studio 3.3

我刚刚在我的电脑上安装了 Android Studio 3.3 和 Java,当我打开一个新项目时,立即出现了这个错误。

ERROR: Gradle DSL method not found: 'testImplementation()'
Possible causes:
The project 'My Application' may be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0).
Upgrade plugin to version 3.4.0 and sync project

The project 'My Application' may be using a version of Gradle that does not contain the method.
Gradle settings

The build file may be missing a Gradle plugin.
Apply Gradle plugin

当我尝试手动更新时,我下载了 gradle 5.4.0 并手动安装。 (我还检查了 cmd 以查看其版本。)

然后我变了

buildscript {
    ext.kotlin_version = '1.3.31'
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}  

这些代码到 gradle:5.4.0 我仍然遇到同样的错误。我该如何解决?

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:5.4.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
  1. application/build.gradle应该在这一行(见gradle插件版本为3.4.0)

顶级构建文件,您可以在其中添加所有 sub-projects/modules.

通用的配置选项
buildscript {
    ext.kotlin_version = '1.3.20'
    repositories {
        google()
        jcenter()
        
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
allprojects {
    repositories {
        google()
        jcenter()
        //maven { url "https://jitpack.io" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
  1. application/gradle/wrapper/gradle-wrapper.properties 应该在这一行(见gradle version as 5.1.1)

3 月 24 日星期日 01:41:54 IST 2019

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
  1. 你的 application/app/build.gradle(你在 github 上发布的)没有问题

如果您有土耳其工作站,请更改 build.gradle:

testImplementation -> testİmplementation
androidTestImplementation -> androidTestİmplementation
androidTestImplementation -> androidTestİmplementation