无法解决:com.android.support.test.espresso

时间:2017-07-14 08:04:29

标签: android android-gradle

我的build.gradle文件如下:

申请插件:' com.android.application'

android {

compileSdkVersion 26

buildToolsVersion '25.0.3'

defaultConfig {

    applicationId "com.xavier.hello"

    minSdkVersion 15

    targetSdkVersion 26

    versionCode 1

    versionName "1.0"

    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

buildTypes {

    release {

        minifyEnabled false

        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

    }

}

}

依赖项{

compile fileTree(include: ['*.jar'], dir: 'libs')

androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',

{

排除群组:' com.android.support',模块:' support-annotations'

})

compile 'com.android.support.constraint:constraint-layout:1.0.2'

testCompile 'junit:junit:4.12'

}

每次都会出现以下错误:

enter image description here

2 个答案:

答案 0 :(得分:2)

当我想尝试Espresso时,我遇到了同样的问题。

我已经通过添加

解决了这个问题
maven {
        url "https://maven.google.com"
    }

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

答案 1 :(得分:0)

这可能是由两个不同的问题引起的:

  1. gradle文件有问题。
  2. 互联网连接问题。

在我的情况下,问题是Internet连接。尝试构建项目时,我实际上已连接到Internet,但是连接速度很慢。有了稳定的wifi后,我再次运行了构建,此问题就消失了。正如Android Studio会告诉您的那样,您可能还需要调整运行在线/离线设置。在项目的build.gradle文件中,您的存储库中应具有以下Maven参考:

repositories {
    jcenter()
    maven {
        url 'https://maven.google.com/'
        name 'Google'
    }
    google() //you may or may not need this line
}