[英]Firebase makes Flutter App build crashes on it's own library code
我正在嘗試使用 firebase 服務構建一個應用程序,並多次嘗試這些步驟,包括在一個全新的項目中進行測試,但我認為庫存在問題:
我在跑步
flutterfire configure
通過項目根文件夾的終端,然后選擇其中一個項目,選擇所有可用平台(android、ios、macos、web),然后同意更新android/build.gradle
和android/app/build.gradle
之后我得到了:
Firebase configuration file lib/firebase_options.dart generated successfully with the following Firebase apps:
但是僅僅導入庫會使構建崩潰
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';
我得到的錯誤是這個
: Error: '$throw' isn't a type.
../…/method_channel/method_channel_firebase.dart:120
$throw coreNotInitialized();
^^^^^^
: Error: Expected ';' after this.
../…/method_channel/method_channel_firebase.dart:120
$throw coreNotInitialized();
^^^^^^^^^^^^^^^^^^
: Error: Expected an identifier, but got ')'.
../…/method_channel/method_channel_firebase.dart:120
Try inserting an identifier before ')'.
$throw coreNotInitialized();
^
示例應用程序就是這樣的:
import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
runApp(MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
appBar: AppBar(title: const Text("My App")),
body: const Center(child: Text("MyApp")),
),
);
}
}
我找到了這個解決方法,我認為當前庫版本或 flutterfire 有問題,但接下來的步驟對我有用:
我更改了以前使用過的版本的 firebase 庫的版本,運行flutter clean
並刪除了Podfile.lock
,它現在可以工作了
不工作的版本
firebase_core: ^2.2.0
firebase_messaging: ^14.2.1
工作版本
firebase_core: ^1.1.0
firebase_messaging: ^9.1.3
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.