简体   繁体   中英

Failed to resolve: com.android.support.test.espresso:espresso-core:3.0.1 Using Android Studio 3.0.1

My gradle project will not sync and throws the following errors:

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

This is not a duplicate of previous questions because I have already included maven which was the solution to this question: Android Studio can't resolve Espresso 3.0.0

Here is my gradle:

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

With including the maven in the repositories, I'm not sure why else this would not be working. What can I do so that android recognizes the espresso dependencies? Thanks!

Edit: Here is the project gradle:

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

        }
    }
}

I'm not sure that I am suppose to add the google() and jcenter() in both blocks but the same error exist with or without them in each block

Update: I tried downloading hamcrest and junit jar files and pointed to those two files for dependencies and that seemed to help with a few issues but I can't find espresso jar files! Still at a loss here unfortunately

This is probably because you're forgetting adding the google() maven in another dependencies block in root / project build.gradle:

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()
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM