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

React Native Firebase Android配置依赖问题:找不到RNFirebasePackage类

Fixing "package io.invertase.firebase does not exist" Error in React Native Firebase

Hey there, let's troubleshoot and fix this compilation error you're facing with your dummy React Native app. The errors you're seeing—missing io.invertase.firebase package and RNFirebasePackage class—almost always stem from outdated setup steps or missing configuration for React Native Firebase (now officially called the Firebase React Native SDK). Here's how to resolve it step by step:

1. Check Your React Native Firebase Version

First, look at your project's package.json to see which version of @react-native-firebase/app you're using:

  • If you're on v10.0.0 or newer: The old RNFirebasePackage setup is no longer required. The SDK uses Auto-Linking to automatically register native modules. You can safely:
    • Remove the line import io.invertase.firebase.RNFirebasePackage; from android/MainApplication.java
    • Remove the new RNFirebasePackage(), line from the getPackages() method in the same file

2. For Older Versions (Pre-v10)

If you're stuck on an older version, make sure you've completed these critical setup steps:

  • Install the core Firebase package if you haven't already:
    npm install @react-native-firebase/app --save
    # Or using Yarn:
    yarn add @react-native-firebase/app
    
  • Update your android/build.gradle to include Google's Maven repositories and the Google Services plugin:
    buildscript {
      repositories {
        // Keep your existing repos, then add:
        google()
      }
      dependencies {
        // Add this line (use a compatible version for your project)
        classpath 'com.google.gms:google-services:4.3.10'
      }
    }
    
    allprojects {
      repositories {
        // Keep your existing repos, then add:
        google()
      }
    }
    
  • Add the Google Services plugin to the end of android/app/build.gradle:
    apply plugin: 'com.google.gms.google-services'
    
  • Ensure you've linked the module (though Auto-Linking should handle this for React Native 0.60+; if not, run npx react-native link @react-native-firebase/app)

3. Clean and Rebuild Your Project

Corrupted build artifacts often cause these kinds of errors. Run these commands to start fresh:

# Navigate to the Android directory
cd android
# Clean the Gradle build cache
./gradlew clean
# Go back to the project root
cd ..
# Rebuild and run the app
npx react-native run-android

4. Verify Your Firebase Config File

Double-check that you've downloaded the google-services.json file from your Firebase project console and placed it in the android/app directory of your dummy app. This file is required for the SDK to connect to your Firebase project.


Why This Happens

In newer versions of the Firebase React Native SDK, the team removed the need for manual package registration in MainApplication.java—Auto-Linking takes care of that. If you followed an outdated tutorial, you might have added code that's no longer valid. For older versions, missing the core package installation or Gradle configuration leads to the compiler not finding the io.invertase.firebase classes.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.28 10:06:03