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

Flutter添加awesome_notifications_fcm后Android编译重复类错误求助

解决awesome_notifications_fcm依赖冲突导致的DuplicateClasses错误

问题根源

你遇到的是依赖版本冲突:awesome_notifications_fcm内部依赖了旧版本的awesome_notifications核心库(0.7.5-dev.3),而项目中同时引入了更高版本的核心库(0.7.7),导致两类库中的重复类被同时打包。

具体解决方法

方法1:通过Flutter依赖覆盖强制统一版本

修改项目根目录的pubspec.yaml,添加dependency_overrides强制指定所有依赖使用同一版本的awesome_notifications:

# pubspec.yaml
dependencies:
  awesome_notifications_fcm: ^你的版本号

dependency_overrides:
  awesome_notifications: ^0.7.7

执行命令刷新依赖:

flutter clean
flutter pub get

方法2:在Android端强制统一依赖版本

修改app/build.gradle,在android块中添加版本解析策略,强制使用0.7.7版本的核心库:

android {
    // ...其他原有配置
    configurations.all {
        resolutionStrategy {
            force 'me.carda.awesome_notifications:core:0.7.7'
        }
    }
}

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

如果方法1、2无效,可直接在app/build.gradle的dependencies块中,排除awesome_notifications_fcm依赖的旧版本核心库,再手动引入指定版本:

dependencies {
    // 排除fcm依赖的旧核心库
    implementation('me.carda.awesome_notifications:fcm:你的版本号') {
        exclude group: 'me.carda.awesome_notifications', module: 'core'
    }
    // 手动引入统一版本的核心库
    implementation 'me.carda.awesome_notifications:core:0.7.7'
}

最后验证

执行以下命令清理缓存后重新编译:

flutter clean
flutter pub get
flutter run

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.16 03:30:58