【问题标题】:Android dependency conflict errorAndroid依赖冲突错误
【发布时间】:2017-05-06 13:45:17
【问题描述】:

我尝试了好几个小时才找到解决方案,但找不到。我的问题是,当我构建 Gradle 时出现两个错误。我试着看看这个解决方案 Dependency conflict error in my Android app which has Android Tests 还是解决不了问题。

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'
}

我该如何解决这个问题?

【问题讨论】:

    标签: android dependencies


    【解决方案1】:

    不要使用 alpha.. 或 beta.. 只使用最新的稳定版本.. 然后请不要混合您的 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"
    

    【讨论】:

      【解决方案2】:

      请去掉这两个依赖

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

      【讨论】:

      • 我的错误。我那里没有那行代码,无论如何这些代码都不会影响这个问题。
      【解决方案3】:

      我找到了解决方案。通过将 compileSdkVersion 升级到

      compileSdkVersion 25 
      

      然后不是这个

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

      仅更新 appcompat-v7:23.1.1 并没有解决。我需要这些 3 行代码。

      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'
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-09-17
        • 2018-01-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-11-24
        相关资源
        最近更新 更多