Flutter集成firebase_core时触发Gradle构建错误::app:checkDebugDuplicateClasses
我之前碰到这个Gradle重复类的错误时,首先确认了Firebase的基础配置流程有没有走对,你可以先跟着过一遍这些操作步骤,确保配置没问题:
Setup
- 在VSCode中创建一个新的Flutter项目,选择Empty Application模板,项目命名为
hello_fire - 运行命令激活flutterfire_cli工具:
dart pub global activate flutterfire_cli - 启动Firebase配置向导:
flutterfire configure
接下来是配置过程中的终端交互记录,你可以参考这个流程来完成项目与Firebase的绑定:
✔ Select a Firebase project to configure your Flutter application with · fir-test-ab0e1 (Firebase Test)
✔ Which platforms should your configuration support (use arrow keys & space to select)? · android, ios, macos, web, windows
✔ Which Android application id (or package name) do you want to use for this configuration, e.g. 'com.example.app'? · com.example.hello_fire
i Firebase android app com.example.hello_fire is not registered on Firebase project fir-test-ab0e1.
i Registered a new Firebase android app on Firebase project fir-test-ab0e1.
i Firebase ios app com.example.helloFire is not registered on Firebase project fir-test-ab0e1.
i Registered a new Firebase ios app on Firebase project fir-test-ab0e1.
i Firebase macos app com.example.helloFire registered.
i Firebase web app hello_fire (web) registered.
如果完成以上配置后仍然出现重复类错误,大概率是依赖版本冲突导致的。你可以尝试以下几点:
- 检查
pubspec.yaml中firebase_core的版本,确保它和其他Firebase依赖版本适配 - 打开Android项目的
build.gradle文件,在dependencies块中通过exclude group:语法排除重复引入的类库 - 执行
flutter clean和flutter pub get清理缓存后重新构建项目
备注:内容来源于stack exchange,提问作者GniLudio

