BX0*_*X07 9 android gradle firebase flutter google-cloud-firestore
我正在 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}.
Run Code Online (Sandbox Code Playgroud)
我努力了:
<uses-permission android:name="android.permission.INTERNET" />所有 3 个 AndroidManifest.xml 文件<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />AndroidManifest.xml 放入 main 下这是我的主要功能:
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}.
Run Code Online (Sandbox Code Playgroud)
我应该正确初始化应用程序,因为我在控制台中得到了他的信息:
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.
Run Code Online (Sandbox Code Playgroud)
该问题可能是由线路引起的W/DynamiteModule(26053): Local module descriptor class for com.google.android.gms.providerinstaller.dynamite not found.,我也无法解决。
这是我的 pubspec.yaml 文件依赖项:
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
name: 'Retrospect',
options: DefaultFirebaseOptions.currentPlatform,
);
runApp(MyApp());
}
Run Code Online (Sandbox Code Playgroud)
我相信我正在使用最新版本的 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'
}
Run Code Online (Sandbox Code Playgroud)
我的 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()
}
}
Run Code Online (Sandbox Code Playgroud)
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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
最后,这是我调用的函数:
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.
Run Code Online (Sandbox Code Playgroud)
导致此错误的原因是什么?(我根本无法通过flutter访问Cloud Firestore)。我没有看到我的防病毒软件 (Windows Defender) 或防火墙阻止任何内容,但如果需要,我可以提供日志。
感谢@Damian 提供的解决方案!
问题出在模拟器上,而不是代码本身
在此处阅读更多信息:Firebase 无法在 Android Studio 模拟器上运行
如何继续解决此问题:
http调用来访问数据。| 归档时间: |
|
| 查看次数: |
8812 次 |
| 最近记录: |