无法解决:com.android.support.test.espresso:espresso-core:3.0.1使用Android Studio 3.0.1

时间:2018-03-09 20:26:58

标签: android gradle android-gradle android-espresso

我的gradle项目不会同步并抛出以下错误:

Failed to resolve:com.android.support.test.espresso:espresso-core:3.0.1
Failed to resolve:com.android.support.test:runner:1.0.1

这不是以前问题的重复,因为我已经包含maven,这是此问题的解决方案:Android Studio can't resolve Espresso 3.0.0

这是我的傻瓜:

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

    dependencies {
        //classpath 'com.android.tools.build:gradle:1.1.0'
        classpath 'com.android.tools.build:gradle:3.0.1'

    }
}

apply plugin: 'com.android.application'


dependencies {

    compile "com.android.support:support-v4:24.2.1"
    compile "com.android.support:support-v13:24.2.1"
    compile "com.android.support:cardview-v7:24.2.1"
    androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.1'
    androidTestCompile 'com.android.support.test:runner:1.0.1'
}

// The sample build uses multiple directories to
// keep boilerplate and common code separate from
// the main sample code.
List<String> dirs = [
    'main',     // main sample code; look here for the interesting stuff.
    'common',   // components that are reused by multiple samples
    'template'] // boilerplate code that is generated by the sample template process

android {
    compileSdkVersion 26
    buildToolsVersion '26.0.2'

    defaultConfig {
        minSdkVersion 25
        targetSdkVersion 26
        applicationId "com.example.android.mediabrowserservice"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"


    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    sourceSets {
        main {
            dirs.each { dir ->
                java.srcDirs "src/${dir}/java"
                res.srcDirs "src/${dir}/res"
//                assets.srcDirs "src/${dir}/assets" //added to show asset folder
            }
        }
        androidTest.setRoot('tests')
        androidTest.java.srcDirs = ['tests/src']

    }


    lintOptions {
        abortOnError false
    }
}

将maven包含在存储库中,我不确定为什么这不会起作用。我能做些什么来让android识别espresso依赖项?谢谢!

编辑:这是项目gradle:

repositories {
    maven {
        url 'https://maven.google.com/'
        name 'Google'
        jcenter()
    }
}
buildscript {
    repositories {
        maven {
            url 'https://maven.google.com/'
            name 'Google'
            jcenter()

        }
    }
}

我不确定我是否想在两个块中添加google()和jcenter()但是在每个块中存在或不存在相同的错误

更新: 我尝试下载hamcrest和junit jar文件,并指出这两个文件的依赖关系,这似乎有助于一些问题,但我找不到espresso jar文件!不幸的是,这里仍然处于亏损状态

1 个答案:

答案 0 :(得分:0)

这可能是因为您忘记在 root / 项目 build.gradle中的其他依赖项块中添加google()maven:

buildscript {

    repositories {
        // this is for the classpath repository
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
    }
}

allprojects {
    // This is for your all module dependencies
    // you probably forget this block.
    repositories {
        google()
        jcenter()
    }
}