0

I created a new project after installing Android Studio 2.3.3 and then the Gradle build failed because of these three errors:

Error:Failed to resolve: junit:junit:4.12 Open File
Show in Project Structure dialog

Error:Failed to resolve: org.hamcrest:hamcrest-library:1.3 Open File
Show in Project Structure dialog

Error:Failed to resolve: org.hamcrest:hamcrest-integration:1.3 Open File
Show in Project Structure dialog

and I tried looking at similar questions and their answers but they didn't work for me. I tried deleting the testCompile line in gradle.build, and I tried adding the url maven "{ url 'http://repo1.maven.org/maven2' }" in the gradle.build file, and I checked the firewall and I downloaded the junit.jar and nothing worked.

Edit:

build.gradle (module)

apply plugin: 'com.android.application'
android {
    compileSdkVersion 25
    buildToolsVersion "26.0.0"
    defaultConfig {
    applicationId "com.example.tasneem.sunshine"
    minSdkVersion 19
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
repositories {
    maven { url 'http://repo1.maven.org/maven2' }


   }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
}

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:2.3.3'

        // 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
}
Tasneem Salah
  • 118
  • 1
  • 10

2 Answers2

0

First of all, connect your internet connection then update your junit library.

0

I figured out a way to fix this. this is not a solution to the error but it will help you run the project if you have the same errors as me and no other method worked. I downloaded a new gradle and extracted it to C:/Users/Username/gradle/wrapper/dist folder then changed the gradle in Android studio from file->settings I also commented the whole testCompile block in the gradle (module) file and removed junit4.12 from the module settings of the project. This seemed to fix the problem and I could run the project on my Android device.

Tasneem Salah
  • 118
  • 1
  • 10