Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

People also ask

What is latest version of JUnit?

JUnit 5 is the latest generation of JUnit. It includes focussing on Java 8 and above with the facility of allowing various types of testing for developers on JVM. The latest release of the JUnit 5 generation is 5.7. 1 which was released in February 2021.


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.


Just remove the "testCompile 'junit:junit:4.12'" from build.gradle file:

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'//remove this line and sync again... worked for me

androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'}) //if available, also delete these two lines

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

worked for me and I am Happy! :)

Remember that this is not the actual answer of this question. I mentioned this because it works when you remove above lines.


Go to File -> Project Structure. Following window will open:

enter image description here

From there:

  1. remove the junit library (select junit and press "-" button below ) and
  2. add it again (select "+" button below, select "library dep.", search for "junit", press OK ). Press OK to apply changes. After around 30 seconds your gradle sync should work fine.

Hope it works for you too :D


It's not able to get junit library.

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

After adding above line inside android block in build.gradle file, it resolved problem. This can be because your Android studio doesn't have junit library.


add repository in your build.gradle file

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

Probably your gradle is incomplete, I recommend you add the following

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

but in some cases won't work , you can completely delete it from you dependencies in your gradle.

I think it will be OK if you reinstall the android studio with the deleting gradle folder condition which is in user folder .gradle


Here is what I did to solve the same problem. I am behind a firewall, which is same issue as yours I suppose. So I had tried removing the

testCompile 'junit:junit:4.12' line 

but that didnt work for me. I tried adding below lines of code:

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

Even that did not work for me.

I tried removing (-) and readding (+) Junit4.12 from the library dependencies under Module Settings. Still that did not work for me.

Tried syncing and rebuilding project several times. Still did not work for me.

Finally what I did was to manually download the Junit4.12.jar file from mvnrepository website. I put this jar file in the Androids Workspace under the Project folder inside libs folder. Then go to Module Settings > Dependencies Tab > (+) > File Dependency > under Sleect path window, expand the 'libs' folder and you will find the Jar file you copied inside there. Select the File and click 'OK' Now remove the previous version of junit4.12 from the list of dependencies.

You should have one entry "libs\junit-4.12.jar" in the Dependencies list. Now click 'OK'.

Now Gradle will rebuild the project and you should be good to go.

Hope this helps!