Error:(23, 17) Failed to resolve: junit:junit:4.12

fathurzero picture fathurzero · Sep 11, 2015 · Viewed 260.4k times · Source

Why is it that every time I create a new project in Android Studio, it always comes up with:

Error:(23, 17) Failed to resolve: junit:junit:4.12?

When I remove testCompile 'junit:junit:4.12' in dependencies it is not a problem anymore.

build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.okedroid.myapplication"
        minSdkVersion 17
        targetSdkVersion 23
        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.0.1'
}

Answer

mdew picture mdew · Sep 14, 2015

I had the same problem. Solved by adding url for missing repository in the build.gradle file:

android {
    [...]
    repositories {
        maven { url 'http://repo1.maven.org/maven2' }
    }
    [...]
}

That's it.