-4

Failed to resolve: junit:junit:4.12

What is the solution to this problem I have tried several solutions

ThomasEdwin
  • 2,035
  • 1
  • 24
  • 36
abdo 20122
  • 121
  • 2
  • 3
  • 4
  • What were you doing when you hit this error? Are you trying to create a new package like in [This question](https://stackoverflow.com/questions/32519219/error23-17-failed-to-resolve-junitjunit4-12) ? Or [This one?](https://stackoverflow.com/questions/32969162/failed-to-resolve-junitjunit4-12-in-android-studio-1-4-on-ubuntu) Or [This other question?](https://stackoverflow.com/questions/40029657/failed-to-resolve-junitjunit4-12) Do none of the existing solutions do what you want? If not, please explain why your situation is different so we can help you. – Davy M Dec 05 '17 at 12:07
  • 2
    Possible duplicate of [Error:(23, 17) Failed to resolve: junit:junit:4.12](https://stackoverflow.com/questions/32519219/error23-17-failed-to-resolve-junitjunit4-12) – Davy M Dec 05 '17 at 12:09

2 Answers2

0

You most probably forgot to specify a repository where dependencies should be looked for.

Add for example

repositories {
    mavenCentral()
}

or

repositories {
    jcenter()
}

to your build script and junit will resolve properly.

If not, please post more information like your build script, and the outut of the Gradle run with using -i to get info level logging.

Btw. please read and obey http://stackoverflow.com/help/how-to-ask and https://stackoverflow.com/help/someone-answers for the future.

Vampire
  • 35,631
  • 4
  • 76
  • 102
  • buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.3.2' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { jcenter() } } – abdo 20122 Dec 05 '17 at 16:45
  • then please run with `-i` and add the output to your question – Vampire Dec 06 '17 at 20:17
-1

You can simply remove that from Gradle and download this file http://www.java2s.com/Code/JarDownload/junit/junit-4.9.jar.zip or latest version found on there site and add it as library to Gradle and again build the project and it's all done.

This problem may be because. Gradle may be unable to find that, but after adding that downloaded file to your project. You are good to go.

  • What sense would that make? OP uses a tool to resolve dependencies and also transitive ones and it does a pretty good job if you use it right. The recommendation to not use it but doing it manually is total nonsense. ;-) – Vampire Dec 05 '17 at 14:23
  • Where to add this file junit-4.9.jar.zip What is the path? – abdo 20122 Dec 05 '17 at 16:39