简体   繁体   English

无法为 org.gradle.api.Project 类型的项目“:app”的参数找到方法 androidTestCompile()

[英]Could not find method androidTestCompile() for arguments on project ':app' of type org.gradle.api.Project

Today I installed Android Studio and after opening the program I see this error in the messages Gradle sync part ->今天我安装了 Android Studio,打开程序后,我在 Gradle 同步部分的消息中看到了这个错误 ->


Error:(31, 0) Could not find method androidTestCompile() for arguments [com.android.support.test.espresso:espresso-contrib:2.2.2, build_4zwzygftganlohhaghm2dsums$_run_closure3@7658f1d6] on project ':app' of type org.gradle.api.Project.
<a href="openFile:C:\Users\Dany\AndroidStudioProjects\MyApplication3\app\build.gradle">Open File</a>

and my gradle-module has this code in it ->我的 gradle-module 中有这个代码 ->


apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.example.dany.myapplication"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.0', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
    testCompile 'junit:junit:4.12'
}
androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.2'){
    exclude module: 'support-annotations'
    exclude module: 'support-v4'
    exclude module: 'support-v13'
    exclude module: 'recyclerview-v7'
    exclude module: 'appcompat-v7'
}androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.2'){
    exclude module: 'support-annotations'
    exclude module: 'support-v4'
    exclude module: 'support-v13'
    exclude module: 'recyclerview-v7'
    exclude module: 'appcompat-v7'
}

Call androidTestCompile within the dependencies block.dependencies块中调用androidTestCompile In addition, remove the duplicated versions of espresso-contrib:2.2.2 .此外,删除espresso-contrib:2.2.2的重复版本。

Rectified build.gradle修正 build.gradle

dependencies 
{
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.0', 
    {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.2')
    {
    exclude module: 'support-annotations'
    exclude module: 'support-v4'
    exclude module: 'support-v13'
    exclude module: 'recyclerview-v7'
    exclude module: 'appcompat-v7'
   })
    compile 'com.android.support:appcompat-v7:25.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
    testCompile 'junit:junit:4.12'
}

Using this solved my error使用这个解决了我的错误

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    androidTestCompile('com.android.support.test.espresso:espresso-core:2.0',
            {
                exclude group: 'com.android.support', module: 'support-annotations'
            })
    androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.2')
            {
                exclude module: 'support-annotations'
                exclude module: 'support-v4'
                exclude module: 'support-v13'
                exclude module: 'recyclerview-v7'
                exclude module: 'appcompat-v7'
            }

    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
}

我有同样的问题,我用“testInstrumentationRunner”替换“androidTestCompile”解决了它

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法为 org.gradle.api.Project 类型的项目“:app”的参数找到方法 buildTypes() - Could not find method buildTypes() for arguments on project ':app' of type org.gradle.api.Project 在 org.gradle.api.Project 类型的项目“:app”上找不到 arguments 的方法 dataBinding() - Could not find method dataBinding() for arguments on project ':app' of type org.gradle.api.Project Flutter 无法在 org.gradle.Z8A5DA52ED1264741A83 类型的项目 ':app' 上找到 arguments [] 的方法 Properties() - Flutter Could not find method Properties() for arguments [] on project ':app' of type org.gradle.api.Project 找不到参数 org.gradle.api.Project 的方法 android() - Could not find method android() for arguments org.gradle.api.Project 无法为参数org.gradle.api.Project找到方法android() - Could not find method android() for arguments org.gradle.api.Project 在类型为org.gradle.api.Project的根项目&#39;..&#39;上找不到参数[build ..]的方法android() - Could not find method android() for arguments [build..] on root project '..' of type org.gradle.api.Project 错误:无法在 org.gradle.api.Project 类型的根项目上找到 arguments 的方法 install() - Error: Could not find method install() for arguments on root project of type org.gradle.api.Project 如何处理“无法在项目中找到方法android()&#39;的错误:org.gradle.api.Project类型的app&#39;” - How to handle error of “Could not find method android() on project ':app' of type org.gradle.api.Project” 在 org.gradle.api.Project 类型的根项目“xyz”上找不到 arguments [before_plugins_] 的方法 android() - Could not find method android() for arguments [before_plugins_] on root project 'xyz' of type org.gradle.api.Project 错误:(16,0)找不到类型为org.gradle.api.Project的根项目&#39;delta-bartalk&#39;上的参数的方法android() - Error:(16, 0) Could not find method android() for arguments on root project 'delta-bartalk' of type org.gradle.api.Project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM