Firebase 尚未正确初始化。是否已将"google-services.json"文件添加到项目中



运行应用程序时出现此错误。我将google-services.json下载到我的android/app文件夹中。我已放入

应用插件:'com.google.gms.google-services'

到我的app/build.gradle文件中。起初我没有把";应用插件";所以我后来把它放进去,似乎没有什么区别。我还放了

classpath com.google.gms:google services:4.3.5'

into my android/build.gradle. The entire error when i run the app is

E/flutter ( 4213): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: 
[core/not-initialized] Firebase has not been correctly initialized. 
Have you added the 
"google-services.json" file to the project? 
E/flutter ( 4213):     
E/flutter ( 4213): View the Android Installation documentation for more information: 
https://firebase.flutter.dev/docs/installation/android
E/flutter ( 4213): 
E/flutter ( 4213): #0      MethodChannelFirebase.initializeApp 
(package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:88:9)
E/flutter ( 4213): <asynchronous suspension>
E/flutter ( 4213): #1      Firebase.initializeApp (package:firebase_core/src/firebase.dart:41:31)
E/flutter ( 4213): <asynchronous suspension>
E/flutter ( 4213): #2     
main (package:rider_app/main.dart:12:3)
E/flutter ( 4213): <asynchronous suspension>
E/flutter ( 4213): 

(编辑:我看到了更多我可能没有看到的错误,我希望你们能理解它们(

Launching libmain.dart on Android SDK built for x86 in debug mode...
Running Gradle task 'assembleDebug'...
Note: "path"flutter_windows_2.0.4-stable.pub-cachehostedpub.dartlang.org
firebase_core-1.0.3androidsrcmainjavaioflutterpluginsfirebase
coreFlutterFirebaseCorePlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: "path"flutter_windows_2.0.4-stable.pub-cachehostedpub.dartlang.org
firebase_auth-1.0.2androidsrcmainjavaioflutterpluginsfirebase
authFlutterFirebaseAuthPlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
√ Built buildappoutputsflutter-apkapp-debug.apk.
Installing buildappoutputsflutter-apkapp.apk...
Debug service listening on ws://127.0.0.1:55393/AAigea5LZbA=/ws
Syncing files to device Android SDK built for x86...
D/EGL_emulation( 8043): eglMakeCurrent: 0x9c861020: ver 2 0 (tinfo 
0xaa003f90)
E/flutter ( 8043): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled 
Exception: [core/not-initialized] Firebase has not been correctly 
initialized. Have you added the "google-services.json" file to the project? 
E/flutter ( 8043):     
E/flutter ( 8043): View the Android Installation documentation for more 
information: https://firebase.flutter.dev/docs/installation/android
E/flutter ( 8043): 
E/flutter ( 8043): #0      MethodChannelFirebase.initializeApp 
(package:firebase_core_platform_interface/src/method_channel
/method_channel_firebase.dart:88:9)
E/flutter ( 8043): <asynchronous suspension>
E/flutter ( 8043): #1      Firebase.initializeApp (package:firebase_core/src/firebase.dart:41:31)
E/flutter ( 8043): <asynchronous suspension>
E/flutter ( 8043): #2      main (package:riderapp/main.dart:14:3)
E/flutter ( 8043): <asynchronous suspension>
E/flutter ( 8043): 

pubspec,yaml

cupertino_icons: ^1.0.2
firebase_core: ^1.0.3
firebase_auth: ^1.0.2
firebase_database: ^6.1.2
fluttertoast: ^8.0.3

gradle/build.gradle

dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath 'com.google.gms:google-services:4.3.5'
classpath "org.jetbrains.kotlin:kotlin-gradle-                                                                                   plugin:$kotlin_version"
}
}

app/build.gradle

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
// this is incase i get error archives can't exceed 64k
implementation 'com.android.support:multidex:1.0.3'
}
//apply plugin:
apply plugin: 'com.google.gms.google-services'

扑动干净-我试过了flutter获取包裹-我试过了扑动医生-v-我尝试

感谢@Nishutan S为我发布解决方案。正如你在评论中看到的那样,他提出了什么建议。

尝试颤动创建。然后flutter清理然后flutter运行如果这不起作用,你可以尝试备份你的lib文件夹和pubspec删除项目,用相同的包名创建一个新项目,并替换lib和pubspec

在我按照他的建议做了之后,我去重新阅读了新项目的图像、字体和声音。我键入flutter pub get以检查pubspec.yaml是否正常工作。我把firebase的依赖关系读入了正确的文件,这可以在他们的网站上找到,具体取决于你自己的项目。现在这个项目正在进行中。感谢大家的帮助

在主函数中添加await Firebase.initializeApp();

示例:

void main() async{
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}

firebase_core: ^1.0.3https://pub.dev/packages/firebase_core

相关内容

最新更新