android - 错误 :Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath' : Could not resolve junit:junit:4. 12

标签 android gradle

我创建了一个新的 android 项目,它在构建时显示错误

我尝试了现有的答案

错误是

Error:Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve junit:junit:4.12.

Error:Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve junit:junit:4.12.

Error:Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve junit:junit:4.12.

Error:Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.google.code.findbugs:jsr305:2.0.1.

我的 gradle 文件的依赖部分

 dependencies 
    {
       implementation 'androidx.appcompat:appcompat:1.0.2'
    testImplementation 'junit:junit:4.12'

    }

我不明白这是我的第一个项目。

我的项目gradle是

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com'
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

我的应用程序 gradle 是

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.0"
    defaultConfig {
        applicationId "com.example.myapplication"
        minSdkVersion 28
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}
android
        {
            configurations.all
                    {
                        resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
                    }
        }

dependencies
        {
    implementation 'androidx.appcompat:appcompat:1.0.2'
    testImplementation 'junit:junit:4.12'


}

最佳答案

在您的 build.gradle 文件中添加以下存储库,

repositories {
      jcenter()
      maven {
        url 'https://maven.google.com'
    }
}

你忘了把这个添加到你的依赖项中

androidTestCompile 'com.google.code.findbugs:jsr305:3.0.0' 

问题是由 espresso library 引起的,如果你不能删除它,请将它添加到你的应用程序 gradle

android
{ 
 configurations.all 
  { 
    resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9' 
  }
}

关于android - 错误 :Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath' : Could not resolve junit:junit:4. 12,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56513672/

相关文章:

android - NDK 文件未与 Gradle Android 同步

android - 如何在我的 Android 应用程序中使用 SoundCloud?

android - 定义自定义操作字符串时是否需要包含应用程序包前缀

angularjs - Gradle不更新Angular依赖关系

plugins - 如何查看Gradle Jetty插件中使用的Jetty版本

ant - Gradle等待ANT任务完成

java - Sonarqube 没有同时选择 Kotlin 和 Java Coverage gradle 项目

android - 在我选择选项卡之前加载进度条

android - Android中的透明布局?

android - Gradle构建卡在app:tranformDexArchiveWithDexMergerForDebug