1
Error:(24, 17) Failed to resolve: junit:junit:4.12
"openFile:/home/jeevansai/AndroidStudioProjects/MyApplication/app/build.gradle"

The above mentioned error is appearing in Android Studio has many issues making a project. Can someone tell a solution to it.

output of cat /home/jeevansai/AndroidStudioProjects/MyApplication/app/build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion '23.0.1'

    defaultConfig {
        applicationId "com.example.jeevansai.myapplication"
        minSdkVersion 8
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    final def types = buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    types
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.android.support:design:23.0.1'
}

output of apt-cache policy junit4

junit4:
  Installed: 4.12-2ubuntu1
  Candidate: 4.12-2ubuntu1
  Version table:
 *** 4.12-2ubuntu1 0
        500 http://in.archive.ubuntu.com/ubuntu/ wily/main amd64 Packages
        100 /var/lib/dpkg/status
  • 1
    Post the contents of your gradle file so we can see what it's trying to do, but there's a possible solution on stackoverflow – AJefferiss Oct 7 '15 at 15:06
  • Edit your question and add the output of cat /home/jeevansai/AndroidStudioProjects/MyApplication/app/build.gradle – A.B. Oct 7 '15 at 15:14
  • sorry slow internet – identicon Oct 7 '15 at 15:50
  • intellij android studio , i did not do any configuration in it – identicon Oct 7 '15 at 16:03
  • 1
    Or someone provide me the link to download complete android sdk ,i mean all packages without the need for android studio to download. – identicon Oct 7 '15 at 16:21
1

Gradle is a build tool integrated in Android Studio: it downloads your project dependencies (the jar files you use in your code) from the maven repositories (maven is another well-known build tool with package dependencies capabilities and a remote ecosystem of repositories). One of the most used repository is jcenter().

Your gradle file lack of a repository configuration: add this piece of code to your gradle file (/home/jeevansai/AndroidStudioProjects/MyApplication/app/build.gradle): between apply plugin and android {...} section.

apply plugin: 'com.android.application'

repositories {
     jcenter()
}

android {
     compileSdkVersion 21
...

Alternatively, if you does not code the unit tests at the moment, you can simple comment out the junit dependency on the app/build.gradle file:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    //testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.android.support:design:23.0.1'
}

Anyhow, you can always download the needed artifact from maven central and put in your /libs directory:

wget 'http://central.maven.org/maven2/junit/junit/4.12/junit-4.12.jar' -O /home/jeevansai/AndroidStudioProjects/MyApplication/app/libs/junit-4.12.jar
  • not working same error shows up – identicon Oct 7 '15 at 18:16
  • I've accessed now a project created with Android Studio: can you paste the content of the build.gradle in the directory above app: /home/jeevansai/AndroidStudioProjects/MyApplication/build.gradle – Giuseppe Ricupero Oct 7 '15 at 18:27
  • I've updated my answer, waiting for your (project) root build.gradle, check if one of the solutions proposed works. The link to download the junit jar file can be found on a search engine of maven repos. I ofter use mvnrepository.com – Giuseppe Ricupero Oct 7 '15 at 18:53
  • I commented out the junit dependency and it works! – hasanghaforian Feb 22 '16 at 18:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.