[英]Flutter app crashes for iOS build on startup
我正在處理應用程序,它以正確的方式工作。 但后來我確實將 mac 更新到 macOS Monterey 12.2.1,並將我的 iPhone 設備更新到最新的 15.2 和 Xcode 13.0,並使用了最新的 13.2.1。 但是現在應用程序在啟動時運行崩潰,甚至在登錄后運行崩潰,但這讓我發瘋。
重點是它在 xcode 上構建時不起作用,而在從 Android 工作室運行時它工作正常。 下面是我正在研究的規格:
[✓] Flutter (Channel stable, 2.8.1, on macOS 12.2.1 21D62 darwin-x64, locale en-GB)
• Flutter version 2.8.1 at /Users/username/development/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 77d935af4d (3 months ago), 2021-12-16 08:37:33 -0800
• Engine revision 890a5fca2e
• Dart version 2.15.1
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at /Users/username/Library/Android/sdk
• Platform android-31, build-tools 30.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 13.0)
• Xcode at /Users/username/Desktop/Xcode.app/Contents/Developer
• CocoaPods version 1.11.2
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2021.1)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)
[✓] VS Code (version 1.63.2)
• VS Code at /Users/neosoft/Downloads/Visual Studio Code.app/Contents
• Flutter extension version 3.34.0
[✓] Connected device (1 available)
• Chrome (web) • chrome • web-javascript • Google Chrome 99.0.4844.51
我一直在使用 Firebase Firestore 作為數據存儲。 接下來我可以嘗試什么?
在大多數情況下,我的最終解決方案總是刪除整個 ios 文件夾(確保備份徽標、資產……),運行flutter create -i swift.
重新創建 ios 文件夾,並運行flutter clean
。
每次遇到錯誤時,我都會以隨機順序多次執行這些步驟,然后就解決了。
在 iOS > AppDelegate.swift 中,在 GeneratedPluginRegistrant.register(with: self) 之前添加 FirebaseApp.configure() 方法
FirebaseApp.configure()
GeneratedPluginRegistrant.register(with: self)
或者:
flutter clean
cd ios
,然后運行 $pod installflutter run
請備份項目,刪除pubSpec.lock
,然后從 ios 文件夾中刪除“Podfile.lock”、 pods
目錄和 Xcworkspace。 然后運行flutter pub get
然后導航到 ios 文件夾並運行pod install
。 然后嘗試在 xcode 中構建它。
似乎在構建它時參考了 ios 的派生數據。 希望按照以下步驟操作,這將起作用
Derive data
podfile.lock
flutter clean
到您的項目終端flutter pub get
pod install
然后嘗試從 Xcode 構建。
您使用的是哪個版本的 flutter? 您是否在 xcode 項目中添加了 firebase plist 文件?
此錯誤是針對pod安裝的,當您運行flutter項目時,它將所有功能安裝為iOs應用程序中的pod包,您必須准確從flutter安裝pod正確,因此您必須正確清除所有pods文件夾並清除所有pods緩存事情取決於 pod,之后您必須升級 cocoa 並安裝或運行 flutter 應用程序。
也許使用 podfile 中的此配置可以解決您的問題:
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '13.0'
end
end
end
In iOS 14+, debug mode Flutter apps can only be launched from Flutter tooling, IDEs with Flutter plugins or from Xcode.
或者,構建配置文件或發布模式以啟用從主屏幕啟動。
可能是因為 flutter 沒有給你顯示這段文字,你認為這是一個錯誤
或者rm -rf Podfile.lock
然后pod install
打開ios/Runner/AppDelegate.swift
。
您需要放置此代碼:
FirebaseApp.configure()
在此之前:
GeneratedPluginRegistrant.register(with: self)
您將在AddDelegate.swift
中看到如下內容:
import UIKit
import Flutter
import Firebase
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
FirebaseApp.configure()
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.