@firebase/firestore:Firestore (9.6.8):无法访问 Cloud Firestore 后端。后端在 10 秒内未响应。错误反应原生 AVD



我在使用react native时遇到了这个错误。Firebase通过auth((正常连接,但我似乎无法让它为firestore工作。该问题仅发生在Android Emulator上,iOS Emulator运行良好。错误只发生在Android虚拟设备上,iOS一个完美工作

这是Firebase文件(删除了有关应用程序的一些信息(

import { initializeApp } from 'firebase/app';
import { getAuth } from 'firebase/auth';
import { getFirestore } from 'firebase/firestore';
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
apiKey: '',
authDomain: '',
projectId: '',
storageBucket: '',
messagingSenderId: '',
appId: '',
measurementId: '',
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const auth = getAuth();
const db = getFirestore(app);
export { auth, db };

这是我使用Firestore函数的地方

import React, { useState } from 'react';
import { useTailwind } from 'tailwind-rn/dist';
import useAuth from '../../hooks/useAuth';
import { doc, serverTimestamp, setDoc } from 'firebase/firestore';
import { db } from '../../Firebase';
import { useNavigation } from '@react-navigation/native';
const ModalScreen = () => {
const tw = useTailwind();
const [image, setImage] = useState('');
const [job, setJob] = useState('');
const [age, setAge] = useState('');
const navigation = useNavigation();
const inCompleteForm = !image || !job || !age;
const updateUserProfile = () => {
setDoc(doc(db, 'users', user.uid), {
id: user.uid,
displayName: user.displayName,
photoURL: image,
job,
age,
timestamp: serverTimestamp(),
})
.then(() => {
navigation.navigate('Home');
})
.catch(err => {
alert(err.message);
});
};
import {
View,
Text,
SafeAreaView,
TouchableOpacity,
Image,
StyleSheet,
Platform,
} from 'react-native';
import React, { useRef, useState, useLayoutEffect } from 'react';
import { useTailwind } from 'tailwind-rn/dist';
import { useNavigation } from '@react-navigation/native';
import useAuth from '../../hooks/useAuth';
import Icon from 'react-native-vector-icons/Ionicons';
import Swiper from 'react-native-deck-swiper';
import { doc, onSnapshot } from 'firebase/firestore';
import { db } from '../../Firebase';
const HomeScreen = () => {
const navigation = useNavigation();
const tw = useTailwind();
const [profiles, setProfiles] = useState([]);
const { user, logOut } = useAuth();
const swipeRef = useRef(null);
useLayoutEffect(() => {
onSnapshot(doc(db, 'users', user.uid), snapshot => {
if (!snapshot.exists) navigation.navigate('Modal');
});
}, []);

错误

[2022-03-15T06:49:42.961Z]  @firebase/firestore: Firestore (9.6.8): Could not reach Cloud Firestore backend. Backend didn't respond within 10 seconds.
This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.
WARN  [2022-03-15T06:53:06.868Z]  @firebase/firestore: Firestore (9.6.8): Connection WebChannel transport errored: {"defaultPrevented": false,

我遇到了同样的问题,试着看看这里,或者如果它能解决问题,我会在下面给出代码:(

import { initializeFirestore } from 'firebase/firestore'
const database = initializeFirestore(app, {
experimentalAutoDetectLongPolling: true
})

const";数据库";在我的例子中;db";在您的代码中,保留两个

最新更新