【问题标题】:Error:Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve junit:junit:4.12错误:无法解析“:app@debugAndroidTest/compileClasspath”的依赖关系:无法解析junit:junit:4.12
【发布时间】:2019-10-24 02:28:55
【问题描述】:

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

我尝试了现有的答案

错误是

错误:无法解决依赖关系 ':app@debugAndroidTest/compileClasspath': 无法解析 junit:junit:4.12.

错误:无法解决依赖关系 ':app@releaseUnitTest/compileClasspath': 无法解析 junit:junit:4.12.

错误:无法解决依赖关系 ':app@debugUnitTest/compileClasspath': 无法解析 junit:junit:4.12.

错误:无法解决依赖关系 ':app@debugAndroidTest/compileClasspath': 无法解析 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'


}

【问题讨论】:

  • 只需删除与测试编译器相关的所有内容
  • 我做到了,但仍然出现这些错误@AlexJolig

标签: android gradle


【解决方案1】:

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

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

您忘记将其添加到您的依赖项中

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

问题是由 espresso 库引起的,如果您无法将其删除,请将其添加到您的应用程序 gradle 中

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

【讨论】:

  • 评论不用于扩展讨论;这个对话是moved to chat
  • 添加 maven 为我修复了它。奇怪的是,问题出在 Android Studio 附带的模板项目的第一次构建期间。
【解决方案2】:

我试图混合 AppCompat 和 Jetpack 依赖项,但你不能这样做。

我想我可能没有为 Jetpack 库设置正确的存储库(为什么它找不到任何 Jetpack 库)。

不要使用:实现 'androidx.appcompat:appcompat:1.0.2' 。 (这是 Jetpack)- 使用 AppCompat 版本(此外 - Jetpack 与 28.x 之前的 Appcompat 版本不一致)。最重要的是,摆脱任何说 (androidx) 的东西。

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
}

【讨论】:

    猜你喜欢
    • 2019-04-19
    • 2018-12-04
    • 2018-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多