一、准备工作

1. 安装firebase

yarn add @react-native-firebase/app

2. 创建应用并下载配置文件

ios => GoogleService-Info.plist
Android => google-services.json

二、Android配置

1. 保证包名一致

2. 放置配置文件

/android/app/google-services.json

3. 修改/android/build.gradle

buildscript {
  dependencies {
    // ... other dependencies
    classpath 'com.google.gms:google-services:4.4.2'  // <- Add this line
  }
}

4. 修改/android/app/build.gradle

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services' // <- Add this line

三、IOS配置

1.保证包名一致

2.使用xcode打开项目/ios/{projectName}.xcworkspace

在这里插入图片描述
在这里插入图片描述

1、点击右侧项目名称->右键选择 add files to ‘{projectName}2、选择下载的GoogleService-Info.plist,勾选Copy items if needed

3.修改/ios/{projectName}/AppDelegate.swift

import ReactAppDependencyProvider
import Firebase // <- Add this line
...
	override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
	FirebaseApp.configure() // <- Add this line
...

4.修改/ios/Podfile

...
`use_frameworks! :linkage => :static` // <- Add this line
$RNFirebaseAsStaticFramework = true // <- Add this line
pod 'GoogleUtilities', :modular_headers => true //这行官方文档没有,但是不加pod install会报错
use_react_native!(
...

四、编译运行

cd ios & pod install
yarn android
yarn ios
Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐