ios - firebase 未正确初始化:Googleservice-Info.plist 不在使用 VScode 的 MacOS 上
问题描述
我正在使用 macOS Big Sur、Visual Studio Code 和当前稳定的 Flutter 版本。
- 我已经搞定了 :
flutter clean, rm -rf Pods Podfile.lock;
flutter pub get; pod init; pod update;
pod install; turned it off and back on;
pulled it out and blew on it then stuck it back in
我的 Podfile 已针对当前 ios 进行了更新,并且我已将“GoogleService-Info.plist”文件复制到几乎每个目录,包括 Runner/lib/main、Flutter/ 等。
我已经多次重启了我的 mac 和 vs 代码,检查了 pubspec.yaml 的准确性,重新运行冻结的自动生成的文件。
使用 Visual Studio 和 Xcode 中的 iPhone 12 模拟器为 ios 编译时会发生此错误。
使用 Visual Studio 和 Android Studio 的 Pixel 3 Emulator 为 android 编译时,不会发生错误,并且程序按预期编译/工作。
我没有在 XCode 上尝试过这种编译 - 我更喜欢在 Mac 上使用 VSCode,并希望留在一个适用于所有平台的开发程序环境中(Visual Studio 代码)
我在编译时收到的错误是:
Launching lib/main.dart on iPhone 12 in debug mode...
package:notes2/main.dart:1
Xcode build done. 62.0s
7.3.0 - [Firebase/Core][I-COR000012] Could not locate configuration file: 'GoogleService-Info.plist'.
Connecting to VM Service at ws://127.0.0.1:51910/4RdXrGyMG2A=/ws
7.3.0 - [Firebase/Core][I-COR000005] No app has been configured yet.
[VERBOSE-2:ui_dart_state.cc(186)] Unhandled Exception: [core/not-initialized] Firebase has not been correctly initialized. Have you added the "GoogleService-Info.plist" file to the project?
View the iOS Installation documentation for more information: https://firebase.flutter.dev/docs/installation/ios
#0 MethodChannelFirebase.initializeApp
package:firebase_core_platform_interface/…/method_channel/method_channel_firebase.dart:88
<asynchronous suspension>
#1 Firebase.initializeApp
package:firebase_core/src/firebase.dart:41
<asynchronous suspension>
#2 main
package:notes2/main.dart:13
<asynchronous suspension>
我已经彻底阅读了 iOS 安装文档,它没有说明将这个文件放在哪里或 Visual Studio 代码开发环境的任何环境变量设置。
任何有使用 VSCode 的经验的人都将不胜感激。我确信它在 Mac 上的 XCode 中运行良好。
我的播客文件
platform :ios, '14.0'
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}
def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end
File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
end
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end
require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)
flutter_ios_podfile_setup
target 'Runner' do
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end
我的 pubspec.yaml 文件
name: notes2
description: A new Flutter project.
publish_to: "none" # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1
environment:
sdk: ">=2.12.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
another_flushbar: 1.10.17
cupertino_icons: 1.0.2
dfunc: 0.6.2
firebase_auth: 1.0.1
firebase_core: 1.0.2
flutter_bloc: 7.0.0
freezed_annotation: 0.14.1
get_it: 6.0.0
google_sign_in: 5.0.1
injectable: 1.2.2
oxidized: 4.1.0
uuid: 3.0.2
dev_dependencies:
flutter_test:
sdk: flutter
build_runner: 1.12.2
freezed: 0.14.1+1
injectable_generator: 1.2.2
lint: 1.5.3
flutter:
uses-material-design: true
assets:
- GoogleService-Info.plist
解决方案
我不知道您是否从 VS 代码中添加了“GoogleService-Info.plist”,但您必须使用 Xcode 添加此文件
要做到这一点:
- 使用 Xcode 打开文件 /$project_name/ios/Runner.xcworkspace
- 右键单击 Runner 文件夹
- 单击将文件添加到 Runner。
- 选择“GoogleService-Info.plist”文件并点击添加。
推荐阅读
- javascript - 尝试多次附加一个 html 表,但是当我重新单击它时,我的 'th' 总是出现在顶部而不是在 'tr' 之后
- python - 我无法使用 kivy 显示数据库
- c - STM32F103RB - 如何知道使用哪个引脚发送触发信号
- java - 如何计算结果 % 第 10,000,001 个素数的阶乘答案
- javascript - 从我的项目中删除所有 componentWillMount,如果我的子组件依赖于 api 响应,那么替换是什么
- flutter - Flutter - 如何实时、定期、在后台运行将位置更新发送到后端。(在安卓和IOS上)
- amazon-web-services - Micronaut 无法处理调用 Lambda 的 AWS Http API 网关 V2
- output - Verilog 条件分配输出 X 应该有 1
- c++ - 运行时错误:将无符号偏移添加到 0x603000000040 溢出到 0x603000000034 (stl_vector.h)
- reactjs - 为什么 setState 只更新改变原始状态