[英]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.