2017-05-06 183 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"