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

React Native 0.69集成firebase推送插件报compile配置不存在

问题相关依赖版本
{
  "react": "18.0.0",
  "react-native": "0.69.0",
  "react-native-firebase-push-notifications": "^2.0.2"
}
报错场景

安装react-native-firebase-push-notifications依赖后,执行npx react-native run-android启动安卓端时构建失败,报错信息如下:

error Failed to install the app. Make sure you have the Android development 
environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build failed with an exception.

Where:
 Build file '/Users/hafizsameed/Documents/right-hand/rn-0.69.0- 
 project/app/node_modules/react-native-firebase-push- 
 notifications/android/build.gradle' 
 line: 179

 What went wrong:
 A problem occurred configuring project ':react-native-firebase-push-notifications'.

  Configuration with name 'compile' not found.

核心报错点:Gradle配置:react-native-firebase-push-notifications项目时,找不到名为compile的配置项,直接导致构建中断。

现有Gradle配置

项目根目录android/build.gradle

repositories {
 google()
 mavenCentral()
  }
dependencies {
  classpath("com.android.tools.build:gradle:7.1.1") 
  classpath("com.facebook.react:react-native-gradle-plugin")
  classpath("de.undercouch:gradle-download-task:5.0.1")
  // NOTE: Do not place your application dependencies here; they belong
  // in the individual module build.gradle files
 classpath 'com.google.gms:google-services:4.3.3'
   }
 }

allprojects {
 repositories {
  maven {
   // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm 
   url("$rootDir/../node_modules/react-native/android")
   } 
 maven {
  // Android JSC is installed from npm
  url("$rootDir/../node_modules/jsc-android/dist")
  } 
 mavenCentral {
 // We don't want to fetch react-native from Maven Central as there are
  // older versions over there.
 content {
   excludeGroup "com.facebook.react"
 }
  }
 google()
  maven { url 'https://www.jitpack.io' }
 }

app模块build.gradle新增配置

apply plugin: 'com.google.gms.google-services'

implementation 'com.google.firebase:firebase-analytics:17.2.2'
报错原因

RN 0.69 配套使用的Android Gradle Plugin 7.1.1已经完全移除了废弃多年的compile依赖配置,仅支持implementation、api等新的依赖声明方式。而react-native-firebase-push-notifications库长期未更新,库自身的安卓构建脚本还在使用已经被删除的compile配置,因此构建时直接报错,和本地安卓开发环境配置没有关系。
另外当前引入的firebase-analytics:17.2.2版本过旧,和Gradle 7.x也存在兼容隐患。

解决方案
  • 临时修复(快速跑通项目)
    1. 打开路径node_modules/react-native-firebase-push-notifications/android/build.gradle,定位到第179行
    2. 检索文件内所有以compile 开头的依赖声明,全部替换为implementation
    3. 为了避免重新安装依赖后修改丢失,在项目根目录执行npx patch-package react-native-firebase-push-notifications将修改打成持久化补丁,后续执行依赖安装命令时补丁会自动生效
  • 长期方案(推荐)
    这个第三方推送库已经停止维护,对新版RN、新版Gradle的兼容问题会越来越多,建议直接替换为Firebase官方维护的React Native推送相关依赖,兼容性和稳定性都有保障,替换时注意使用和RN 0.69匹配的依赖版本即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.27 18:48:54