簡體   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