错误:(23, 17) 无法解决:junit:junit:4.12

错误:(23, 17) 无法解决:junit:junit:4.12

问题描述:

为什么每次我在Android Studio中创建一个新项目时,总是出现:

Why is it that every time I create a new project in Android Studio, it always comes up with:

错误:(23, 17) 无法解析:junit:junit:4.12?

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

当我删除依赖项中的 testCompile 'junit:junit:4.12' 时,它不再是问题.

When I remove testCompile 'junit:junit:4.12' in dependencies it is not a problem anymore.

build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.okedroid.myapplication"
        minSdkVersion 17
        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.0.1'
}

我遇到了同样的问题.通过在 build.gradle 文件中添加缺少存储库的 url 解决:

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' }
    }
    [...]
}

就是这样.