Flutter Build APK:未处理的异常:[核心/未初始化] Firebase 尚未正确初始化

Ham*_*mza 5 android apk dart firebase flutter

我只在发布模式下遇到这个问题,在调试模式下它工作正常。

\n

我仅使用firebase_core插件firebase_storage

\n

\xe2\x9a\xa0 异常

\n

在此输入图像描述

\n

颤振医生

\n

在此输入图像描述

\n

遵循将 Firebase 集成到 Flutter 中的所有步骤:

\n

步骤1:

\n

main.dart之前添加的runApp()

\n
    \n
  • WidgetsFlutterBinding.ensureInitialized();
  • \n
  • await Firebase.initializeApp();
  • \n
\n
void main() async {\n  WidgetsFlutterBinding.ensureInitialized();\n  await Firebase.initializeApp();\n  runApp(MyApp());\n}\n
Run Code Online (Sandbox Code Playgroud)\n

第2步:

\n

添加到build.gradle根文件夹

\n
    \n
  • classpath \'com.google.gms:google-services:4.2.0\'
  • \n
\n
buildscript {\n    ext.kotlin_version = \'1.3.50\'\n    repositories {\n        google()\n        jcenter()\n    }\n\n    dependencies {\n        classpath \'com.android.tools.build:gradle:4.1.0\'\n        classpath \'com.google.gms:google-services:4.2.0\' <-- // here it is\n        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"\n    }\n}\n\n
Run Code Online (Sandbox Code Playgroud)\n

步骤3:

\n

添加到build.gradle应用程序级别

\n
    \n
  • apply plugin: \'com.google.gms.google-services\'
  • \n
\n
apply plugin: \'com.android.application\'\napply plugin: \'com.google.gms.google-services\' <--- // here it is\napply plugin: \'kotlin-android\'\napply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"\n\n
Run Code Online (Sandbox Code Playgroud)\n

步骤4:

\n
    \n
  • 更新了firebase_core
  • \n
  • 更新了firebase_storage
  • \n
\n

第5步:

\n

添加google-service.json到应用程序级别

\n

在此输入图像描述

\n

我已经浏览过 Stack Overflow 上提供的解决方案。因此,无论您要共享什么链接,我可能已经浏览过了。

\n

如果您还需要任何其他信息,请告诉我:)

\n