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

升级@react-native-firebase后安卓项目报messaging编译错误如何解决

@react-native-firebase安卓端编译报错修复方案
  • 调整firebase依赖导入顺序,必须将bom声明放在所有firebase相关依赖最前面,确保bom的版本管控生效,修改app/build.gradle配置如下:
implementation platform('com.google.firebase:firebase-bom:31.2.3')
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-messaging'
implementation 'androidx.multidex:multidex:2.0.1'
  • 升级buildToolsVersion适配当前compileSdk版本,你当前使用的compileSdk为31,对应buildToolsVersion需升级到31.0.0,修改项目根目录build.gradle的ext块配置:
buildscript {
    ext {
        buildToolsVersion = "31.0.0"
        minSdkVersion = 23
        compileSdkVersion = 31
        targetSdkVersion = 31
        kotlinVersion = '1.5.0'
        ndkVersion = "20.1.5948944"
    }
    // 其余原有配置保持不变
}
  • 统一所有@react-native-firebase前缀依赖的版本号,确保项目中安装的@react-native-firebase/app、@react-native-firebase/messaging、@react-native-firebase/analytics等包版本完全一致,避免跨版本兼容问题。
  • 清理全量缓存后重新构建,依次执行以下命令:
cd android
./gradlew clean
cd ..
rm -rf node_modules package-lock.json yarn.lock
# 执行对应包管理器安装命令,npm install 或 yarn install
npx react-native run-android
  • 若上述操作后仍报错,可升级gradle插件版本适配compileSdk 31,修改根目录build.gradle的dependencies块配置:
dependencies {
    classpath("com.android.tools.build:gradle:4.2.2")
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
    classpath 'com.google.gms:google-services:4.3.10'
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.03 23:06:03