Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
未找到Gradle DSL方法:';androidTestImplementation()';_Android_Android Studio_Android Gradle Plugin_Android Testing - Fatal编程技术网

未找到Gradle DSL方法:';androidTestImplementation()';

未找到Gradle DSL方法:';androidTestImplementation()';,android,android-studio,android-gradle-plugin,android-testing,Android,Android Studio,Android Gradle Plugin,Android Testing,我正在尝试使用uiautomator,所以在这里查看了教程 在教程中,它说: 在Android应用程序模块的build.gradle文件中,必须设置对UI自动机库的依赖项引用: 我添加了这一行,我的build.gradle文件如下: // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext.kotlin_vers

我正在尝试使用uiautomator,所以在这里查看了教程

在教程中,它说:

在Android应用程序模块的build.gradle文件中,必须设置对UI自动机库的依赖项引用:

我添加了这一行,我的build.gradle文件如下:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext.kotlin_version = "1.3.72"
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.0.2"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

//        androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
//        androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
        androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
//        androidTestImplementation('androidx.test.uiautomator:uiautomator:2.2.0')

        // 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
}
我试着运行这个应用程序。但我有一个错误:

Gradle DSL method not found: 'androidTestImplementation()'
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 4.0.2 and sync project

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

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

您使用的文件错误
build.gradle
和块错误

您必须将
androidTestImplementation
从顶级文件移动到
依赖项
块中的
模块/build.gradle
文件(而不是
构建脚本
块中的
依赖项
):


将依赖项实现移动到应用程序级别build.gradle文件。您已经将它们放在项目级build.gradle文件中

Gradle DSL method not found: 'androidTestImplementation()'
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 4.0.2 and sync project

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

The build file may be missing a Gradle plugin.
Apply Gradle plugin
   apply plugin: 'com.android.application'
   apply plugin: 'kotlin-android'

   android {
    //...
   }

    dependencies {
        //...
        androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
    }