【发布时间】:2021-04-05 15:05:11
【问题描述】:
我已经放松了这些步骤并观看了几个有关如何将 react-native 应用程序连接到 firebase 的视频。 但我仍然收到此错误:
Error: You attempted to use a firebase module that's not installed on your Android project by calling firebase.app().
Ensure you have:
1) imported the 'io.invertase.firebase.app.ReactNativeFirebaseAppPackage' module in your 'MainApplication.java' file.
2) Added the 'new ReactNativeFirebaseAppPackage()' line inside of the RN 'getPackages()' method list.
See http://invertase.link/android for full setup instructions.
▶ 4 stack frames were collapsed.
App
C:/Users/saadb/Desktop/Smart-Mirror-App/App.js:8
5 |
6 | export default function App() {
7 |
> 8 | const users = firestore()
9 | .collection('Users')
10 | .get();
所以,我尝试修复错误并将其添加到我的 MainApplication
import io.invertase.firebase.messaging.RNFirebaseMessagingPackage;
import io.invertase.firebase.notifications.RNFirebaseNotificationsPackage;
@Override
protected List<ReactPackage> getPackages() {
@SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
packages.add(new ModuleRegistryAdapter(mModuleRegistryProvider));
packages.add(new RNFirebaseMessagingPackage());
packages.add(new RNFirebaseNotificationsPackage());
return packages;
}
这是我的 App.js 文件
import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import firestore from '@react-native-firebase/firestore';
export default function App() {
const users = firestore()
.collection('Users')
.get();
// console.log(users);
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',
},
});
我还添加了所有依赖项和包以及 google.json 文件,如说明。 谁能帮我解决这个问题。
【问题讨论】:
标签: java android react-native react-native-android