Android支持库Gradle冲突

4
我在我的应用中遇到了关于Android支持库版本不一致的问题,但是即使在Gradle中指定了完全相同的版本,我仍然会得到同样的错误。
问题出现在 'com.android.support:appcompat-v7:23.1.0' 和 'com.android.support:support-v4:24.0.0' 之间。即使指定了 'compile 'com.android.support:support-v4:23.1.0'',它仍然说与 'support-v4:24.0.0' 存在冲突。如果能够提供任何帮助解决这个问题,将不胜感激。

enter image description here

编辑:以下是我的完整 build.gradle 文件。

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
    maven { url 'https://maven.fabric.io/public' }
}

def keystorePropertiesFile = rootProject.file("keystore.properties");
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

android {
    signingConfigs {
        config {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreProperties['storeFile'])
            storePassword keystoreProperties['storePassword']
        }
    }
    compileSdkVersion 23
    buildToolsVersion '25.0.2'
    defaultConfig {
        applicationId "com.company"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 48
        versionName "5.1.5"
        multiDexEnabled true
    }
    buildTypes {
        release {
            debuggable false
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.config
        }
    }
    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
    }

}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.0'


    compile 'com.android.support:support-v4:23.1.0'
    compile 'com.android.support:design:23.1.0'
    compile 'com.android.support:support-annotations:23.1.0'

    compile 'com.parse.bolts:bolts-android:1.4.0'
    compile files('libs/Parse-1.13.0/Parse-1.13.0.jar')

    compile 'com.pkmmte.view:circularimageview:1.1'

    compile 'com.google.code.gson:gson:2.7'

    // SugarORM
    compile 'com.github.satyan:sugar:1.5'

    compile 'com.android.support:multidex:1.0.1'

    // Firebase
    compile 'com.google.firebase:firebase-core:10.2.0'
    compile 'com.google.firebase:firebase-messaging:10.2.0'

    // Google play services
    compile 'com.google.android.gms:play-services-location:10.2.0'
    compile 'com.google.android.gms:play-services-places:10.2.0'

    // Timber logging
    compile 'com.jakewharton.timber:timber:4.5.0'

    compile 'joda-time:joda-time:2.9.7'

    // Crashlytics
    compile('com.crashlytics.sdk.android:crashlytics:2.6.7@aar') {
        transitive = true;
    }
}

apply plugin: 'com.google.gms.google-services'

请发布您的应用程序模块的 build.gradle 文件。 - Abhishek Aryan
@AbhishekAryan 完成 - myrocks2
2
你的一个或多个传递依赖项正在请求 Android Support Library 的某个部分的 24.0.0 版本,而你自己并没有直接请求,导致了这个冲突。你需要运行 Gradle 依赖报告并找出是什么原因导致了这个问题,然后手动使用你想要的版本(目前为 23.1.0)请求这些构件。请注意,你可能会破坏那些依赖关系,因为它们期望得到更新的版本(24.0.023.1.0 更新)。 - CommonsWare
啊,我明白了。为了避免破坏这些依赖项,我可以安全地忽略版本冲突警告,对吗? - myrocks2
@myrocks2 请考虑投票并接受帮助您的答案。 - Mahdi-Malv
3个回答

3

您需要在Linux中使用以下命令从依赖树中检查依赖关系:

./gradlew app:dependencies

如果你正在使用Windows,可以尝试以下方法:

gradlew.bat app:dependencies

在找到依赖项 support-v4:24.0.0 后,您可以使用以下方式将其排除:

compile('com.library.name:version') {
  //exclude group: 'com.android.support'
  //exclude module: 'support-v7'
  //exclude module: 'appcompat-v7'
  exclude module: 'support-v4'
}

谢谢,你救了我们的一天... 最后的解决方案非常完美。 - RAINA

0
在这种库版本与其他版本不同的情况下,我建议您将该库添加到依赖项中,并将其版本设置为其他版本相同。
在您的情况下,您可以添加所有版本为25.3.1的库。

0

看看你的 android DSL:

android {
    compileSdkVersion 25
    buildToolsVersion '25.0.2'
}

如果buildToolsVersion是25+,那么compileSdkVersion也应该是25+。
由于buildToolsVersion是25+,那么您的支持库也应该是25+。
dependencies {
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:support-v4:25.3.1'
    compile 'com.android.support:design:25.3.1'
    compile 'com.android.support:support-annotations:25.3.1'
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接