[英]Flutter -Firebase/FireStore - Could not reach Cloud Firestore backend. Backend didn't respond within 10 seconds
[英]Could not reach Cloud Firestore backend. Backend didn't respond within 10 seconds - Flutter Android Studio
我在 Android Studio 中使用 flutter。
我在我的控制台中得到這個:
W/Firestore(26053): (24.2.2) [OnlineStateTracker]: Could not reach Cloud Firestore backend. Backend didn't respond within 10 seconds
W/Firestore(26053):
W/Firestore(26053): 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.
E/flutter (26053): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: [cloud_firestore/unavailable] The service is currently unavailable. This is a most likely a transient condition and may be corrected by retrying with a backoff.
E/flutter (26053): #0 checkIfDocExists (package:crypto_app/Functions/firestorehelper.dart:29:5)
E/flutter (26053): <asynchronous suspension>
E/flutter (26053): #1 _MainPagesState._checkUsername (package:crypto_app/UI/mainpages.dart:63:21)
E/flutter (26053): <asynchronous suspension>
E/flutter (26053):
W/Firestore(26053): (24.2.2) [WatchStream]: (a4a9ed6) Stream closed with status: Status{code=UNAVAILABLE, description=Channel shutdownNow invoked, cause=null}.
我試過了:
<uses-permission android:name="android.permission.INTERNET" />
放入所有 3 個 AndroidManifest.xml 文件中<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
放在 AndroidManifest.xml 下的 main這是我的主要功能:
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
name: 'Retrospect',
options: DefaultFirebaseOptions.currentPlatform,
);
runApp(MyApp());
}
我應該正確初始化應用程序,因為我在我的控制台中得到了他:
I/FirebaseApp(26053): Device unlocked: initializing all Firebase APIs for app Retrospect
I/flutter (26053): Refreshing
W/DynamiteModule(26053): Local module descriptor class for com.google.android.gms.providerinstaller.dynamite not found.
I/DynamiteModule(26053): Considering local module com.google.android.gms.providerinstaller.dynamite:0 and remote module com.google.android.gms.providerinstaller.dynamite:0
W/ProviderInstaller(26053): Failed to load providerinstaller module: No acceptable module com.google.android.gms.providerinstaller.dynamite found. Local version is 0 and remote version is 0.
問題可能是由行W/DynamiteModule(26053): Local module descriptor class for com.google.android.gms.providerinstaller.dynamite not found.
,我也無法解決。
這是我的 pubspec.yaml 文件依賴項:
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
firebase_core: ^1.20.1
cloud_firestore: ^3.4.4
http: ^0.13.4
path_provider: ^2.0.11
get_storage: ^2.0.3
我相信我使用的是最新版本的 firebase_core 和 cloud_firestore。
我的 app/build.gradle 文件依賴和插件:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'com.google.gms.google-services'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "com.android.support:multidex:1.0.3"
implementation 'com.google.android.material:material:1.6.1'
implementation 'com.google.android.gms:play-services-ads:21.1.0'
implementation platform('com.google.firebase:firebase-bom:30.3.2')
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.google.firebase:firebase-storage-ktx'
}
我的 build.gradle 文件:
buildscript {
ext.kotlin_version = '1.6.10'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.13'
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
google-services.json 文件位置:
這是我在 Firestore 中的規則(規則應該不是問題,因為我能夠使用 python 成功讀取數據。
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if
request.time < timestamp.date(2022, 12, 12);
}
}
}
最后,這是我調用的函數:
import 'package:cloud_firestore/cloud_firestore.dart';
Future<bool> checkIfDocExists(String docId) async {
try {
// Get reference to Firestore collection
var collectionRef = FirebaseFirestore.instance.collection('accounts');
var doc = await collectionRef.doc(docId).get();
return doc.exists;
} catch (e) {
throw e;
}
}
是什么導致了這個錯誤? (我根本無法通過 flutter 訪問 Cloud Firestore)。 我沒有看到我的防病毒軟件 (Windows Defender) 或防火牆阻止任何東西,但如果需要,我可以提供日志。
這幾天我也遇到了同樣的問題。 我一直在尋找有同樣問題的人,但沒有找到任何人。 但是,我必須從我的 Firebase 項目應用程序設置中再次下載 google-services.json 文件,似乎它解決了錯誤。 我再也看不到它了。 但仍然面臨通過 FutureBuilder 獲取數據的問題。 希望對你有幫助
感謝@Damian 的解決方案!
問題是模擬器,而不是代碼本身
在此處閱讀更多信息: Firebase 不適用於 Android Studio Emulator
如何繼續這個問題:
http
調用來訪問數據。我認為我的問題是因為我試圖將另一個 Firebase 項目覆蓋到我的應用程序中。
如果您嘗試添加不同的 Firebase 應用程序並從 flutter 應用程序中刪除第一個應用程序,則不應簡單地刪除google-services.json
文件並添加第二個項目的文件。 請在線查看如何在您的 flutter 應用程序中更改您的 Firebase 項目。
我可以通過能夠訪問該項目的雲功能而不是我的新 Firebase 項目來驗證我的原始 Firebase 應用程序是否仍然存在。
解決此問題的可能方法:
如果您沒有過度使用 Firestore,您可以嘗試通過雲函數http
調用訪問數據。
您也可以嘗試重新啟動一個新項目並使用正確的 Firebase 項目。
在應用程序上啟用 appcheck 有助於解決我的問題
將模擬器或設備的互聯網連接切換到更強大的替代方案可以修復它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.