Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to resolve : junit:junit:4.12 in android studio 1.4 on ubuntu

When i am creating new project in android studio 1.4 on ubuntu.

I am getting this error when gradle's sync completed on

testCompile 'junit:junit:4.12' 

with message on app/build.gradle

Error:(23, 17) Failed to resolve: junit:junit:4.12
Show in File
Show in Project Structure dialog

// build gradle (app module)

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {
    applicationId "com.example.abhishek.vearch"
    minSdkVersion 16
    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'
compile 'com.android.support:design:23.0.1'
}

// build gradle (project)

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
repositories {
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:1.3.0'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}

allprojects {
repositories {
    jcenter()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}
  • I have tried Error:(23, 17) Failed to resolve: junit:junit:4.12
like image 539
Abhishek Avatar asked Oct 06 '15 11:10

Abhishek


3 Answers

Some people have solved by adding below block for missing URL for repository.

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

Just to mention : Right click on 'app' folder and goto 'Open Module Settings'. Then move to last tab 'Dependencies' and re-add junit by searching. I tried to add earlier versions but failed to get it working.

like image 54
krozaine Avatar answered Nov 16 '22 18:11

krozaine


if you're using open JDK 8 it could be because of a bug with the cacerts. Maybe you could try the following to fix the broken cacerts:

$ sudo dpkg --purge --force-depends ca-certificates-java
$ sudo apt-get install ca-certificates-java

I tried changing my jcenter() to the one with the url as well as trying to change it to maven { url ... } and both didn't work. This one fixed it for me.

See: https://stackoverflow.com/a/33440168

like image 26
E.J Avatar answered Nov 16 '22 20:11

E.J


In my case I was behind a proxy and the issue has been resolved using both

jcenter {
    url "http://jcenter.bintray.com/"
}

and

repositories {
    maven { url 'http://repo1.maven.org/maven2' }
}
like image 1
SaverioL Avatar answered Nov 16 '22 18:11

SaverioL