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

时间:2017-08-23 08:34:18

标签: android android-gradle

今天我安装了Android Studio,打开程序后,我在消息Gradle sync part - >中看到了这个错误。

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>

我的gradle-module中包含此代码 - &gt;

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'
}

3 个答案:

答案 0 :(得分:1)

apt-get区块内呼叫androidTestCompile。此外,请删除dependencies的重复版本。

整顿build.gradle

espresso-contrib:2.2.2

答案 1 :(得分:0)

使用此命令解决了我的错误

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'
}

答案 2 :(得分:0)

我遇到了同样的问题,我将“ androidTestCompile”替换为“ testInstrumentationRunner”来解决了这个问题