9

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
}
Community
  • 1
  • 1
Abhishek
  • 2,350
  • 2
  • 21
  • 35

5 Answers5

6

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.

krozaine
  • 1,481
  • 15
  • 22
1

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' }
}
Infinite Recursion
  • 6,511
  • 28
  • 39
  • 51
SaverioL
  • 11
  • 1
1

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

Community
  • 1
  • 1
E.J
  • 33
  • 5
0

If you are facing issue with junit:junit4.12. This is the solution.

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

Add these above two line after

apply plugin: 'com.android.application' 
saibaba vali
  • 2,641
  • 1
  • 17
  • 17
-2

//remove this line- testCompile 'junit:junit:4.12'

and sync again... worked for me-

dependencies 

{

compile fileTree(dir: 'libs', include: ['*.jar'])

testCompile 'junit:junit:4.12'   //remove this line from here

compile 'com.android.support:appcompat-v7:23.0.1'

}
Mauker
  • 11,237
  • 7
  • 58
  • 76
  • ya i know that but why would i remove that ? then what if i want to test ? – Abhishek Oct 09 '15 at 06:28
  • I seriously doubt that is a solution. One guess is that it was using Junit 3 methods, which should be included in android.jar (for example in Api 19), while not needing Junit 4.x. Or perhaps newer android Apis even have Junit 4. – cowst Oct 12 '15 at 14:47