![](/img/trans.png)
[英]Conflict with dependency 'com.google.code.gson:gson' in project ':app'. Resolved versions for app (2.7) and test app (2.8.0) differ
[英]Warning: Conflict with dependency 'junit:junit' in project ':app'. Resolved versions for app (4.11) and test app (4.12)
我正在嘗試解決兩個錯誤:
在我的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.