繁体   English   中英

警告:与项目':app'中的依赖项'junit:junit'冲突。 app(4.11)和test app(4.12)的已解决版本

[英]Warning: Conflict with dependency 'junit:junit' in project ':app'. Resolved versions for app (4.11) and test app (4.12)

我正在尝试解决两个错误:

  1. 无法解析符号'test'
  2. 无法解析符号'AndroidJUnit4'

在我的Android Studio项目中运行集成测试。 为了解决这个问题,我已经看到了一些答案,我的build.gradle看起来像:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion '25.0.0'

    defaultConfig {
        applicationId "com.ps.comunio.comuniops"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            debuggable true
        }
    }
    compileOptions.with {
        sourceCompatibility = JavaVersion.VERSION_1_7
        targetCompatibility = JavaVersion.VERSION_1_7
    }
    lintOptions {
        abortOnError false
    }

}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.11'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.loopj.android:android-async-http:1.4.9'
    compile 'info.cukes:cucumber-java:1.2.0'
    compile 'info.cukes:cucumber-junit:1.2.0'
    androidTestCompile 'com.android.support.test:runner:0.5'
    androidTestCompile 'com.android.support.test:rules:0.5'
    androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
}

这样可以解决这两个错误,但会出现警告:

错误:与项目':app'中的依赖项'junit:junit'冲突。 app(4.11)和测试app(4.12)的已解决版本有所不同。

谢谢!

一种解决方案是强制Gradle编译junit:junit:4.11而不是junit:junit:4.12

为此,请在应用的build.gradle中添加以下内容:

android {
    configurations.all {
        resolutionStrategy.force 'junit:junit:4.11'
    }
}

去掉

testCompile 'junit:junit:4.11'

compile 'junit:junit:4.11'

[用编译替换testCompile]

有了您的问题,您可以尝试:

file>>project Structure>>app>>dependencies>>click button "+" >>library dependence>>input junit>>click junit 4.12>>done

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在项目':app'中与依赖'com.google.code.gson:gson'冲突。 app(2.7)和测试app(2.8.0)的已解决版本不同 与项目':app'中的依赖项冲突。 app(15.0.2)和测试app(12.0.1)的已解决版本不同(可能是信号和firebase问题) 错误:与项目':app'中的依赖项'com.android.support:support-v4'发生冲突。 应用(25.3.1)和测试应用(23.1.1)的已解决版本不同 与项目':app'中的依赖'com.android.support:support-annotations'冲突。 app(26.1.0)和测试app(27.1.1)的已解决版本有所不同。 错误:在项目':app'中与依赖项'com.google.guava:guava'发生冲突。 应用(18.0)和测试应用(16.0.1)的已解决版本不同 错误:无法解析':app @ debugAndroidTest / compileClasspath'的依赖项:无法解析junit:junit:4.12 适用于Android应用程序的JUnit测试 Espresso错误:与依赖项“ com.android.support:support-v4”发生冲突。 应用(24.2.0)和测试应用(23.1.1)的已解决版本不同 与依赖'com.android.support:support-annotations'冲突。 app(23.3.0)和测试app(23.1.1)的已解决版本有所不同 与依赖'com.android.support:support-annotations'冲突。 app(23.1.0)和测试app(23.0.1)的已解决版本有所不同
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM