tldr;使用 iPhone XS Max ios 12.1 模拟器将 Flutter 应用程序连接到 Firebase 的步骤。 YMMV,使用风险自负。
我能够解决我的问题并让我的 Swift/Xcode 10/iOS 12/iPhone XS Max Flutter 项目连接到 Firebase,尽管它最终是 Swift/Xcode 10.1/iOS 12.1/iPhone XS Max。由于 Firebase、Swift、Xcode、Cocoapods 和 RVM 是相互关联/相互依赖的,我不确切知道我所做的哪些事情或事情的组合解决了我的问题,所以我概述了我的所有步骤,以便如果你也是在使用类似配置连接到 Firebase 时遇到问题,这些步骤中的一个或多个可能有助于解决您的问题。
1) 通过将Applications/Xcode、~/Library/Developer/ 和~/Library/Caches/com.apple.dt.Xcode 拖到垃圾箱,卸载现有的 Xcode 应用程序(和 Xcode 命令行工具)。根据您拥有的 Xcode 版本,您可能有也可能没有最后一个文件。
2) 使用brew uninstall cocoapods 在终端中卸载 Cocoapods。 (如果您使用 RVM 而不是 Homebrew 安装 Cocoapods,则不需要)
3) 安装了 Xcode 10.1。打开它以安装其他工具。跑sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer、sudo xcodebuild -license(多次向下翻页并输入“同意”)和sudo DevToolsSecurity -enable。
4) 已安装 Xcode 10.1 命令行工具。
5) 跑rvm get stable --auto-dotfiles。我的 .zshrc 文件(可能是您的 .bashrc 或 .bash_profile 文件)的底部看起来像这样(下面没有其他行):
export PATH="$PATH:$HOME/.rvm/bin"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
6) 由于我使用 zsh 而不是 bash,所以运行source ~/.zshrc 来更新当前终端会话,然后运行rvm cleanup all。 Ran echo $PATH 验证我想要的 gemset 是路径中的第一个条目。
(更新:gemset 不再是我路径中的第一个条目,但一切仍在正常运行。不确定这对其他事情是否至关重要,但似乎不会影响这种情况。)
7) 使用 gem install -n /usr/local/bin cocoapods -v 1.6.0.beta.2 重新安装 Cocoapods。
8) 用gem update 更新了所有宝石。
9) 使用 brew update && brew upgrade && brew cleanup; brew doctor 更新了 Homebrew、我的公式和我的木桶。
10) 冉pod setup。
11) 要将我的 Xcode 模拟器默认设备设置为“iPhone XS Max”,运行xcrun simctl list --json 以生成可用模拟器设备的列表。在“iOS 12.1”下找到与 iPhone XS Max 关联的 UDID,将 UUID 复制并粘贴到此命令 xcrun simctl boot DB8E7F47-DD01-4952-9BE8-5BCEB6BDBDB0 并运行它。
(更新:此步骤似乎不再需要。当您在下面第 17 步中的 IntelliJ Idea 项目中打开 iOS 模拟器时,您应该能够通过选择“硬件 > 设备 > iOS 12.1 > iPhone”来选择设备XS Max”在 iOS 模拟器中。)
12)在IntelliJ Idea项目中,打开pubspec.yaml文件,添加firebase_core: ^0.2.5+1如下:
dependencies:
flutter:
sdk: flutter
firebase_core: ^0.2.5+1
然后在 IntelliJ Idea IDE 中选择“Packages get”。
13) 按照 Firebase 步骤 1 将 iOS 应用添加到项目“注册应用”:
- 在 IntelliJ Idea 项目中右键单击
/ios/Runner 文件夹
- 选中“Flutter > 在 Xcode 中打开 iOS 模块”
- 点击左侧面板顶部的“Runner”图标
- 在中心面板的“常规”选项卡下,复制了“身份”下顶部第二行中的捆绑标识符,看起来像“com.company.app”。 (如果您没有看到“常规”选项卡,请单击中心面板顶部第二行上的“跑步者”,而不是第一行的那个,然后选择“目标 - Runner”而不是“Project - Runner”。)
- 在 Firebase 步骤 1 中输入“Register app - iOS bundle ID”中的粘贴包标识符
- 将其他输入留空,点击“注册应用”按钮。
14) 遵循 Firebase 步骤 2:
- 已将
GoogleService-Info.plist 下载到桌面
- 在 Xcode 中(参见下面的注释),右键单击 inner Runner 文件夹
(左面板“跑步者 > 跑步者”)
- 已选择“将文件添加到 Runner...”
- 添加了
GoogleService-Info.plist 文件。
注意:原来是直接下载GoogleService-Info.plist到IntelliJ项目中的/ios/Runner文件夹,但是这样导致了一个错误,描述并解决了here。虽然在完成第 2 步后,GoogleService-Info.plist 确实 出现在 Xcode 的 Runner 文件夹中,但它不 出现在 IntelliJ 项目的 /ios/Runner 文件夹中。我不确定这是否会造成未来的问题,但目前不会。
15) 遵循 Firebase 步骤 3:
- 在 IntelliJ 终端中,运行
cd ios,然后运行 pod init。 (如果您已经有 Podfile,则可以跳过此步骤,但如果最终无法正常工作,您可能需要返回此步骤并生成新的 Podfile。)
- 打开 Podfile 并取消注释顶部的“platform :ios”行并将值更改为 '12.1'
- 仍在 Podfile 中,已添加
pod 'Firebase/Core'
Podfile 代码放置的片段:
target 'Runner' do
use_frameworks!
pod 'Firebase/Core'
- 打开
project_name/ios/flutter/release.xconfig并添加行#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"
- 跑
pod install
16) 遵循 Firebase 步骤 4:
- 在 Firebase 应用设置屏幕中,从 Swift 版本的
AppDelegate 初始化代码复制 import Firebase
- 粘贴到
project_name/ios/runner/AppDelegate.swift
- 在 Firebase 应用设置屏幕中,从 Swift 版本的 AppDelegate` 初始化代码中复制了
FirebaseApp.configure()
- 粘贴到
project_name/ios/runner/AppDelegate.swift
AppDelegate.swift 文件代码放置的片段:
import UIKit
import Flutter
import Firebase // <--
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
FirebaseApp.configure() // <--
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
17) 在 IntelliJ 中,选择右上角下拉菜单中的“打开 iOS 模拟器”。 iOS 模拟器使用“iPhone XS”打开。我在 iOS 模拟器中使用“硬件 > 设备 > iOS 12.1 > iPhone XS Max”更改了设备。
18) 在 IntelliJ 终端中,运行“flutter doctor -v”,输出如下:
[✓] Flutter (Channel dev, v1.1.9, on Mac OS X 10.14.2 18C54, locale en-US)
• Flutter version 1.1.9 at /Users/my-macbookpro/flutter
• Framework revision 1407091bfb (2 weeks ago), 2019-01-08 20:40:19 -0800
• Engine revision e5ec3cf3ea
• Dart version 2.1.1 (build 2.1.1-dev.0.1 2cb346bd0c)
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at /Users/my-macbookpro/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.0.3
• ANDROID_HOME = /Users/my-macbookpro/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
• All Android licenses accepted.
[✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 10.1, Build version 10B61
• ios-deploy 1.9.4
• CocoaPods version 1.6.0.beta.2
[✓] Android Studio (version 3.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 29.1.1
• Dart plugin version 181.5656
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
[✓] IntelliJ IDEA Community Edition (version 2018.3.4)
• IntelliJ at /Applications/IntelliJ IDEA CE.app
• Flutter plugin version 31.3.4
• Dart plugin version 183.5429.25
[✓] Connected device (1 available)
• iPhone XS Max • DB8E7F47-DD01-4952-9BE8-5BCEB6BDBDB0 • ios • iOS 12.1 (simulator)
• No issues found!
19) 在 IntelliJ 中,单击右上角的“运行”绿色箭头图标。程序构建完成后,检查 Firebase 安装网页,收到确认消息“恭喜,您已成功将 Firebase 添加到您的应用!”
按照这些步骤,应用和 Firebase 之间的连接似乎可以正常运行。