错误:无法解析“:app @ debugAndroidTest / compileClasspath”的依赖项:无法解析junit:junit:4.12

时间:2019-06-09 10:05:18

标签: android gradle

我创建了一个新的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'


}

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:0)

我试图混合使用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'
}
相关问题