Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to resolve : Error:(23, 17) junit:junit:4.12 in android studio 1.4 [duplicate]

I am using Android Studio 1.4 and every time I create a new project same error happen

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

I read previous post about same problem
Error:(23, 17) Failed to resolve: junit:junit:4.12

and done all the the given answer but despite adding URL ('http://repo1.maven.org/maven2' and 'http://jcenter.bintray.com/') for missing repository the error remains

here is my latest build.gradle code

apply plugin: 'com.android.application'

android {
  compileSdkVersion 14
  buildToolsVersion "23.0.1"

  defaultConfig {
    applicationId "com.example.myapplication"
    minSdkVersion 14
    targetSdkVersion 14
    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:22.+'
}
like image 340
maia Avatar asked Nov 18 '15 14:11

maia


1 Answers

If you are adding them to buildscript you will get an error.

It is a difference between the buildscript repository and the repositories for the dependencies. The buildscript is used for gradle build dependencies.

You will need to add the following to your build.gradle file and it should work fine.

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

Following should work:

apply plugin: 'com.android.application'

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

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.example.application"
        minSdkVersion 15
        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.1.1'
    compile 'com.android.support:design:23.1.1'
}
like image 85
Nitro Avatar answered Sep 24 '22 22:09

Nitro