我正在使用Expo和Firebase构建一个简单的跨平台应用程序。
我使用的是托管工作流,因为我不想接触原生代码。我还安装了react-native-firebase
,因为这是我进入Firebase的"应用检查"功能的唯一途径。
我已经完全按照Expo和react-native-firebase
的文档设置了我的应用程序,但是当我尝试向Firestore发出一个简单的请求时,我得到了以下错误:
Error: You have attempted to use a firebase module that's not installed on your Android project by calling firebase.app()
确保您拥有:
1.) imported the 'io.invertase.firebase.appReactNativeFirebaseAppPackage module in your MainApplication.java
2.)在RN "getPackages()"方法列表中添加了新的ReactNativeFirebaseAppPackage()行
在设置我的应用程序时,我安装了@react-native-firebase/app
和@react-native-firebase/firestore
,确保在app.json
的插件中包含react-native-firebase
,并将google-services.json
和GoogleService-info.plist
集成到项目的根目录中。
所以我不确定这里发生了什么。我错过了一个步骤吗?react-native-firebase
在托管工作流中不工作吗?或者react-native-firebase
与Firebase v9不兼容吗?我这样说是因为我使用的是名称空间方法来检索数据,而不是模块化:
useEffect(() => {
const getDocs = async () => {
const arr = []
const snapshot = await firestore().collection("test-collection").get()
snapshot.forEach((doc) => arr.push(doc.data()))
setItem(snapshot)
}
getDocs()
},[])
总之,以下是负责Firebase调用的整个组件:
- 应用程序js**
import { useState,useEffect } from 'react'
import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View } from 'react-native';
import firestore from "@react-native-firebase/firestore"
export default function App() {
const [item,setItem ] = useState([])
useEffect(() => {
const getDocs = async () => {
const arr = []
const snapshot = await firestore().collection("test-collection").get()
snapshot.forEach((doc) => arr.push(doc.data()))
setItem(snapshot)
}
getDocs()
},[])
console.log('item',item)
return (
<View style={styles.container}>
<Text>Open up App.js to start working on your app!</Text>
<StatusBar style="auto" />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
- 应用程序json**
{
"expo": {
"name": "test-app",
"slug": "test-app",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
"userInterfaceStyle": "light",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": [
"**/*"
],
"ios": {
"googleServicesFile": "./GoogleService-Info.plist",
"supportsTablet": true,
"bundleIdentifier": "com.****.testapp"
},
"android": {
"googleServicesFile": "./google-services.json",
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#FFFFFF"
},
"package": "com.*****.testapp"
},
"web": {
"favicon": "./assets/favicon.png"
},
"plugins": [ "@react-native-firebase/app"],
"extra": {
"eas": {
"projectId": "****"
}
}
}
}
1条答案
按热度按时间oxf4rvwz1#
react-native-firebase
使用本机模块,并且需要使用预嵌入的react-native-firebase
编译自定义Expo Go开发客户端。分步指南-https://www.youtube.com/watch?v=id0Im72UN6w
否则,请使用不带本地模块的官方Firebase JavaScript SDK。