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

添加grpc-google-cloud-speech-v1依赖时重复类错误的解决方法

解决Gradle依赖冲突:Duplicate class com.google.api.Advice

这个冲突是因为proto-google-common-protos和protolite-well-known-types两个库都打包了com.google.api.Advice类,导致编译时出现重复类错误。下面是两种可行的解决方法:

方法一:排除冲突的依赖模块

根据项目核心需求,选择排除其中一个重复的依赖模块:

  • 如果Firebase相关功能是项目必需的,在grpc语音依赖中排除proto-google-common-protos:
    implementation('com.google.api.grpc:grpc-google-cloud-speech-v1') {
        exclude group: 'com.google.api.grpc', module: 'proto-google-common-protos'
    }
    
  • 如果grpc语音服务是项目核心需求,在Firebase依赖中排除protolite-well-known-types(替换成你实际使用的Firebase依赖):
    implementation('com.google.firebase:firebase-analytics') {
        exclude group: 'com.google.firebase', module: 'protolite-well-known-types'
    }
    

方法二:强制统一依赖版本

通过Gradle的force属性强制使用其中一个版本的依赖,覆盖冲突版本:

  • 强制使用Google官方的proto-google-common-protos版本:
    implementation('com.google.api.grpc:proto-google-common-protos:2.31.0') {
        force = true
    }
    
  • 或者强制使用Firebase的protolite-well-known-types版本:
    implementation('com.google.firebase:protolite-well-known-types:18.0.0') {
        force = true
    }
    

验证修复效果

修改配置后,执行./gradlew clean build(Android项目可使用./gradlew clean assembleDebug)检查错误是否消失。如果仍有冲突,运行./gradlew dependencies查看完整依赖树,定位所有引入冲突类的依赖后再针对性处理。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.01 01:42:16