Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio can't resolve Espresso 3.0.0

According to the Android Espresso documentation to date:

Add Espresso dependencies

To add Espresso dependencies to your project, complete the following steps:

  1. Open your app’s build.gradle file. This is usually not the top-level build.gradle file but app/build.gradle.
  2. Add the following lines inside dependencies:
androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.0'
androidTestCompile 'com.android.support.test:runner:1.0.0'

I created a new project and the generated app/gradle file was like this:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.0"
    defaultConfig {
        applicationId "com.app.test"
        minSdkVersion 24
        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'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.+'
    testCompile 'junit:junit:4.12'
}

When I change it to the following:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.0"
    defaultConfig {
        applicationId "com.app.test"
        minSdkVersion 24
        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'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:26.+'
    testCompile 'junit:junit:4.12'
    // App's dependencies, including test
    compile 'com.android.support:support-annotations:22.2.0'

    // Testing-only dependencies
    androidTestCompile 'com.android.support.test:runner:1.0.0'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.0'
}

I get the following errors:

Error:(29, 24) Failed to resolve: com.android.support.test:runner:1.0.0
    Install Repository and sync project
Error:(30, 24) Failed to resolve: com.android.support.test.espresso:espresso-core:3.0.0
    Install Repository and sync project

I have tried clicking on the "Install repository and sync project" link but nothing happens. I have also tried looking through the SDK manager, but I can't really see anything.

like image 787
Quintin Balsdon Avatar asked Aug 02 '17 08:08

Quintin Balsdon


People also ask

How to add project dependency in Android Studio?

Go to File > Project Structure in Android Studio. Select the app module in the Modules list on the left. Select the Dependencies tab. Click the + button on the lower left to add the dependency.

What is AndroidX test?

AndroidX Test is a collection of Jetpack libraries that lets you run tests against Android apps. It also provides a series of tools to help you write these tests. For example, AndroidX Test provides JUnit4 rules to start activities and interact with them in JUnit4 tests.


2 Answers

Simply,
Adding google() into allprojects > repositories will do the trick here...

allprojects {
    repositories {
        google()
        jcenter()
    }
}
like image 27
Paresh P. Avatar answered Sep 18 '22 11:09

Paresh P.


As the solution from comment is solving the problem I am adding it as an answer for others:

Be sure to add Google's maven link to main build.gradle file:

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}
like image 199
R. Zagórski Avatar answered Sep 20 '22 11:09

R. Zagórski