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

React Native集成Firebase推送通知时依赖解析错误求助

问题

我用Firebase实现推送通知,几小时前还一切正常,突然出现配置项目':app'失败的错误,具体是无法解析':app:_debugApk'的所有依赖。配置':react-native-fcm'项目时找不到com.google.firebase:firebase-analytics-impl-license:11.8.0对应的firebase-analytics-impl-license.aar文件,搜索路径是https://jcenter.bintray.com/com/google/firebase/firebase-analytics-impl-license/11.8.0/firebase-analytics-impl-license-11.8.0.aar。

以下是我的app级gradle代码片段:

apply plugin: "com.android.application"
apply plugin: 'com.google.gms.google-services'
import com.android.build.OutputFile

project.ext.react = [
    entryFile: "index.js"
]
apply from: "../../node_modules/react-native/react.gradle"

def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false

android {
    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }
    compileSdkVersion 23
    buildToolsVersion "23.0.1"
    defaultConfig {
        applicationId "co...
    }
}
解决方法

针对这个依赖找不到的问题,你可以按以下步骤尝试修复:

  • 调整仓库优先级:JCenter已经停止维护,很多旧的Firebase依赖可能已经无法访问。确保你的项目根目录的build.gradle里,google()仓库放在jcenter()之前,这样Gradle会优先从Google的仓库拉取依赖:

    allprojects {
        repositories {
            google()
            jcenter()
            // 其他仓库...
        }
    }
    
  • 升级Firebase依赖版本:11.8.0是非常老旧的版本了,Google可能已经移除了这些旧版本的包。建议升级到较新的稳定版本,同时确保react-native-fcm也能兼容。首先检查根目录build.gradle里的Google服务版本:

    dependencies {
        classpath 'com.google.gms:google-services:4.3.15' // 升级到稳定版本
        // 其他classpath...
    }
    

    然后在app级gradle里,确保所有Firebase相关依赖版本一致,比如升级到17.x或更高版本(根据react-native-fcm的兼容情况调整)。

  • 清理Gradle缓存:本地缓存可能损坏,执行以下命令清理缓存后重新构建:

    ./gradlew clean
    ./gradlew build --refresh-dependencies
    
  • 检查react-native-fcm的兼容性:如果react-native-fcm版本太旧,可能和新的Firebase版本不兼容。可以考虑升级react-native-fcm,或者如果该库已经停止维护,换成官方的@react-native-firebase/messaging库(更推荐,因为是官方维护)。

  • 移除不必要的依赖引用:如果你的项目不需要firebase-analytics,可以尝试排除该依赖,在app级gradle的依赖块里添加:

    implementation(project(':react-native-fcm')) {
        exclude group: 'com.google.firebase', module: 'firebase-analytics'
    }
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.29 07:39:16