Flutter firebase firestore软件包在打开应用程序时崩溃,这是日志文件,
E/MethodChannel#plugins.flutter.io/cloud_firestore(28101): Failed to handlemethod call
E/MethodChannel#plugins.flutter.io/cloud_firestore(28101):
java.lang.NullPointerException: Firestore component is not present.
E/MethodChannel#plugins.flutter.io/cloud_firestore(28101): at
com.google.common.base.Preconditions.checkNotNull(Preconditions.java:787)
E/MethodChannel#plugins.flutter.io/cloud_firestore(28101): at com.google.firebase.firestore.FirebaseFirestore.zza(com.google.firebase:firebase-firestore@@17.1.1:86)
E/MethodChannel#plugins.flutter.io/cloud_firestore(28101): at com.google.firebase.firestore.FirebaseFirestore.getInstance(com.google.firebase:firebase-firestore@@17.1.1:78)
E/MethodChannel#plugins.flutter.io/cloud_firestore(28101): at io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin.getFirestore(CloudFirestorePlugin.java:82)
E/MethodChannel#plugins.flutter.io/cloud_firestore(28101): at io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin.getCollectionReference(CloudFirestorePlugin.java:87)
E/MethodChannel#plugins.flutter.io/cloud_firestore(28101): at io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin.getQuery(CloudFirestorePlugin.java:139)
E/MethodChannel#plugins.flutter.io/cloud_firestore(28101): at io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin.onMethodCall(CloudFirestorePlugin.java:463)
E/MethodChannel#plugins.flutter.io/cloud_firestore(28101): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:200)
E/MethodChannel#plugins.flutter.io/cloud_firestore(28101): at io.flutter.view.FlutterNativeView$PlatformMessageHandlerImpl.handlePlatformMessage(FlutterNativeView.java:188)
E/MethodChannel#plugins.flutter.io/cloud_firestore(28101): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:202)
E/MethodChannel#plugins.flutter.io/cloud_firestore(28101): at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#plugins.flutter.io/cloud_firestore(28101): at android.os.MessageQueue.next(MessageQueue.java:326)
E/MethodChannel#plugins.flutter.io/cloud_firestore(28101): at android.os.Looper.loop(Looper.java:160)E/MethodChannel#plugins.flutter.io/cloud_firestore(28101): at android.app.ActivityThread.main(ActivityThread.java:6718)
E/MethodChannel#plugins.flutter.io/cloud_firestore(28101): at java.lang.reflect.Method.invoke(Native Method
E/MethodChannel#plugins.flutter.io/cloud_firestore(28101): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)E/MethodChannel#plugins.flutter.io/cloud_firestore(28101): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
还有更多日志,
E/flutter (28101): [ERROR:flutter/shell/common/shell.cc(186)] Dart Error: Unhandled exception:
E/flutter (28101): PlatformException(error, Firestore component is not present., null)
E/flutter (28101): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:564:7)
E/flutter (28101): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:292:18)
E/flutter (28101): <asynchronous suspension>
E/flutter (28101): #2 Query.snapshots.<anonymous closure> (file:///Users/chathura/Flutter/flutter_sdk/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.8.2+3/lib/src/query.dart:56:37)
E/flutter (28101): #3 _runGuarded (dart:async/stream_controller.dart:805:24)
E/flutter (28101): #4 _BroadcastStreamController._subscribe (dart:async/broadcast_stream_controller.dart:213:7)
E/flutter (28101): #5 _ControllerStream._createSubscription (dart:async/stream_controller.dart:818:19)
E/flutter (28101): #6 _StreamImpl.listen (dart:async/stream_impl.dart:472:9)
E/flutter (28101): #7 _StreamBuilderBaseState._subscribe (package:flutter/src/widgets/async.dart:135:37)
E/flutter (28101): #8 _StreamBuilderBaseState.initState (package:flutter/src/widgets/async.dart:109:5)
E/flutter (28101): #9 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3830:58)
E/flutter (28101): #10 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
E/flutter (28101): #11 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
E/flutter (28101): #12 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
E/flutter (28101): #13 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
E/flutter (28101): #14 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
E/flutter (28101): #15 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
E/flutter (28101): #16 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
E/flutter (28101): #17 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
E/flutter (28101): #18 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
E/flutter (28101): #19 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
E/flutter (28101): #20 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
E/flutter (28101): #21 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
E/flutter (28101): #22 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
E/flutter (28101): #23 ParentDataElement.mount (package:flutter/src/widgets/framework.dart:4047:11)
E/flutter (28101): #24 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
E/flutter (28101): #25 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4965:32)
E/flutter (28101): #26 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
E/flutter (28101): #27 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
E/flutter (28101): #28 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
E/flutter (28101): #29 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
E/flutter (28101): #30 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
E/flutter (28101): #31 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
E/flutter (28101): #32 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
E/flutter (28101): #33 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
E/flutter (28101): #34 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
E/flutter (28101): #35 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
E/flutter (28101): #36 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
E/flutter (28101): #37 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
E/flutter (28101): #38 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
E/flutter (28101): #39 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
E/flutter (28101): #40 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
E/flutter (28101): #41 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
E/flutter (28101): #42 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
E/flutter (28101): #43 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
E/flutter (28101): #44 StatefulElement._firstBuild (package:flutter/src/wi
这是我的应用程序级别gradle文件,
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.google.gms:google-services:4.2.0'
}
allprojects {
repositories {
google()
jcenter()
}
这是模块级gradle文件,
dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
implementation 'com.google.firebase:firebase-core:16.0.7'
}
firestore软件包的版本
cloud_firestore: ^0.9.0
是问题还是插件问题?
任何建议都值得赞赏。
答案 0 :(得分:0)
几件事:
将这些行粘贴到gradle.properties
文件的末尾。
android.useAndroidX=true
android.enableJetifier=true
文件app\build.gradle
android {
compileSdkVersion 28
...
defaultConfig {
minSdkVersion 21
targetSdkVersion 28
multiDexEnabled true
...
}
转到终端并启动命令
flutter clean
然后再次构建。
在cloud_firestore 0.9.0
的{{3}}中提到:
0.9.0#重大更改。从已弃用的原始Android支持库迁移到AndroidX。这不应该导致任何功能 进行更改,但需要使用此插件的所有Android应用程序 如果他们使用的是原始支持库,则进行迁移。