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

2022-08-31 08:02:30

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

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

当我在依赖项中删除时,这不再是问题。testCompile 'junit:junit:4.12'

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'
}

答案 1

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

android {
    [...]
    repositories {
        maven { url 'https://repo1.maven.org/maven2' }
    }
    [...]
}

就是这样。


答案 2

只需从 build.gradle 文件中删除“testCompile 'junit:junit:4.12'”:

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'//remove this line and sync again... worked for me

androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'}) //if available, also delete these two lines

compile 'com.android.support:appcompat-v7:23.0.1'
 }

为我工作,我很高兴!:)

请记住,这不是这个问题的实际答案。我之所以提到这一点,是因为当您删除上面的行时,它有效。


推荐