1

Failed to resolve: junit:junit:4.12

I have attempted numerous solutions from the previous time this question was asked but none of them seem to be working. I tried deleting the entire line Failed to resolve: junit:junit:4.12.

my build.gradle top file:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        // Gradle 4.1 and higher include support for Google's Maven repo using
        // the google() method. And you need to include this repo to download
        // Android plugin 3.0.0 or higher.
        google()
        maven { url "https://maven.google.com" }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
    }
}

my module app build.gradle

apply plugin: 'com.android.application'

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

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.2"
    defaultConfig {
        applicationId "ru.foodrobot.myapplication"
        minSdkVersion 17
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        //google()
        //jcenter()
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

finally this is what I have in my build.gradle app file:

apply plugin: 'com.android.application'

repositories {
    maven { url 'http://repo1.maven.org/maven2' }
    jcenter { url "http://jcenter.bintray.com/" }
}

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"

    defaultConfig {
        applicationId "com.example.application"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
    }
    buildTypes {

        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
}
Anatoly
  • 3,266
  • 4
  • 17
  • 28

2 Answers2

0

In your build.gradle top file try replacing this part:

repositories {
        // Gradle 4.1 and higher include support for Google's Maven repo using
        // the google() method. And you need to include this repo to download
        // Android plugin 3.0.0 or higher.
        google()
        maven { url "https://maven.google.com" }
    }

With this:

repositories {
        // Gradle 4.1 and higher include support for Google's Maven repo using
        // the google() method. And you need to include this repo to download
        // Android plugin 3.0.0 or higher.
        google()
        maven { url "http://repo1.maven.org/maven2" }
    }
LS_
  • 6,763
  • 9
  • 52
  • 88
0

I was able to compile your gradle by this change in your module app build.gradle

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

instead of

repositories {
    maven { url "https://maven.google.com" }
    google()
}
Roberto Martucci
  • 1,237
  • 1
  • 13
  • 21