You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google Drive Android REST V3 依赖冲突无法生成Release APK求助

谷歌Drive V3 API依赖冲突Release打包报错彻底解决方案

步骤1:定位冲突根源

执行项目根目录下的gradle命令导出依赖树,排查重复引入的冲突库:

# Windows系统用 gradlew.bat app:dependencies
./gradlew app:dependencies

重点排查com.google.guava、com.squareup.okhttp3、com.google.code.gson、androidx.* 相关依赖的版本差异。

步骤2:全局统一冲突依赖版本

在模块级build.gradle文件顶部添加版本强制规则,所有依赖统一使用指定版本,避免不同依赖引入多版本同库冲突:

configurations.all {
    resolutionStrategy {
        // 可根据项目实际使用的版本调整下方版本号
        force "com.squareup.okhttp3:okhttp:4.10.0"
        force "com.squareup.okio:okio:3.2.0"
        force "com.google.guava:guava:31.1-android"
        force "com.google.code.gson:gson:2.10.1"
        force "androidx.core:core:1.9.0"
        force "androidx.annotation:annotation:1.5.0"
    }
}

步骤3:精准排除Drive SDK冗余依赖

引入Drive V3 API依赖时,主动排除 SDK 自带的冲突、废弃组件:

implementation('com.google.apis:google-api-services-drive:v3-rev20220812-2.0.0') {
    exclude group: 'com.google.guava', module: 'listenablefuture'
    exclude group: 'org.apache.httpcomponents'
    exclude group: 'com.google.android', module: 'android'
}

步骤4:确认AndroidX兼容配置

检查项目根目录gradle.properties文件,确保已开启AndroidX和Jetifier兼容:

android.useAndroidX=true
android.enableJetifier=true

步骤5:处理打包校验规则

资源/元数据冲突处理

在模块级build.gradle的android代码块中添加打包规则,排除重复的元数据文件:

packagingOptions {
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/LICENSE*'
    exclude 'META-INF/NOTICE*'
    exclude 'META-INF/ASL2.0'
    exclude 'META-INF/AL2.0'
    exclude 'META-INF/LGPL2.1'
    exclude 'META-INF/*.kotlin_module'
}

Lint规则调整

无需全局关闭abortOnError,仅忽略和依赖冲突相关的特定Lint错误即可:

lintOptions {
    abortOnError true
    checkReleaseBuilds false
    // 可根据实际报错的Lint ID追加忽略规则
    ignore 'DuplicatePlatformClasses', 'InvalidPackage', 'DuplicateClasses'
}

内容的提问来源于stack exchange,提问作者Waqas Tahir

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.14 15:15:04