2017-05-06 211 views
1

我試了好幾個小時才找到解決方案但找不到。我的問題是,當我建立我的Gradle時,我得到兩個錯誤。我試圖看看這個解決方案 Dependency conflict error in my Android app which has Android Tests但仍不能解決問題。Android依賴衝突錯誤

Error:Conflict with dependency 'junit:junit' in project ':app'. Resolved versions for app (4.10) and test app (4.12) differ. See http://g.co/androidstudio/app-test-app-conflict for details. 

Error:Conflict with dependency 'org.hamcrest:hamcrest-core' in project ':app'. Resolved versions for app (1.1) and test app (1.3) differ. See http://g.co/androidstudio/app-test-app-conflict for details. 

這裏是我的build.gradle

apply plugin: 'com.android.application' 

android { 
compileSdkVersion 23 
buildToolsVersion "25.0.0" 
defaultConfig { 
    applicationId "voice.com.topsalai" 
    minSdkVersion 16 
    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' 
    } 
} 
} 

dependencies { 
compile fileTree(dir: 'libs', include: ['*.jar']) 
androidTestCompile('com.android.support.test.espresso:espresso-core:2.3- 
alpha', { 
    exclude group: 'com.android.support', module: 'support-annotations' 
}) 

compile 'com.android.support:appcompat-v7:23.1.1' 

compile 'com.android.support.constraint:constraint-layout:1.0.2' 
compile 'com.jakewharton.timber:timber:4.5.1' 
compile 'com.google.android.gms:play-services:10.2.4' 
compile 'com.android.support:support-annotations:26.0.0-alpha1' 
compile 'com.googlecode.json-simple:json-simple:1.1.1' 
compile 'com.android.support:support-v4:23.1.1' 
} 

我該如何解決這個問題?

回答

0

我找到了解決辦法。通過升級compileSdkVersion到

compileSdkVersion 25 

然後取而代之的是

compile 'com.android.support:appcompat-v7:23.1.1' 

只能通過更新程序兼容性-V7:23.1.1沒有解決它。我需要這三行代碼。

compile 'com.android.support:appcompat-v7:25.3.1' 
compile 'com.android.support:animated-vector-drawable:25.3.1' 
compile 'com.android.support:mediarouter-v7:25.3.1' 
0

請刪除這兩個依賴

testCompile 'com.android.support:support-annotations:26.0.0-alpha1' 
androidTestCompile 'com.android.support:support-annotations:26.0.0-alpha1 
+0

我的錯誤。我沒有那些代碼行,並且這些都不會影響這個問題。 –

1

不使用alpha..or公測..只是使用最新的穩定one..then請不要混用的Android版本支持使用..同一版本的所有支持Android

例如

compile "com.android.support:appcompat-v7:25.3.1" 
compile "com.android.support:cardview-v7:25.3.1" 
compile "com.android.support:design:25.3.1" 
compile "com.android.support:recyclerview-v7:25.3.1" 
compile "com.android.support:support-annotations:25.3.1" 
compile "com.android.support:support-v4:25.3.1" 
compile "com.android.support:support-v13:25.3.1"