Flutter iOS端UrlLauncher启动触发EXC_BAD_ACCESS错误求助
崩溃错误日志
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000000
Exception Codes: 0x0000000000000001, 0x0000000000000000
VM Region Info: 0 is not in any region. Bytes before following region: 4373725184
REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL
UNUSED SPACE AT START
--->
__TEXT 104b1c000-104b20000 [ 16K] r-x/r-x SM=COW /Users/USER/Library/Developer/CoreSimulator/Devices/648E4A66-F360-49DA-AD6F-3AC0C3115E9F/data/Containers/Bundle/Application/6B6C2FD1-6A42-4289-8762-44CB26EEFA52/Runner.app/Runner
Termination Reason: SIGNAL 11 Segmentation fault: 11
Terminating Process: exc handler [7323]Triggered by Thread: 0
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libswiftCore.dylib 0x194b2f078 swift_getObjectType + 36
1 url_launcher_ios 0x104d2c088 static URLLauncherPlugin.register(with:) + 96 (URLLauncherPlugin.swift:12)
2 url_launcher_ios 0x104d2c200 @objc static URLLauncherPlugin.register(with:) + 56
3 Runner.debug.dylib 0x104cc3a10 +[GeneratedPluginRegistrant registerWithRegistry:] + 112 (GeneratedPluginRegistrant.m:18)
4 Runner.debug.dylib 0x104cc3a90 AppDelegate.application(:didFinishLaunchingWithOptions:) + 96 (AppDelegate.swift:10)
5 Runner.debug.dylib 0x104cc3d80 @objc AppDelegate.application(:didFinishLaunchingWithOptions:) + 196
6 UIKitCore 0x185ad4c2c -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 312
7 UIKitCore 0x185ad6124 -[UIApplication _callInitializationDelegatesWithActions:forCanvas:payload:fromOriginatingProcess:] + 2936
8 UIKitCore 0x185adb2a4 -[UIApplication _runWithMainScene:transitionContext:completion:] + 976
9 UIKitCore 0x1850ebb0c -[_UISceneLifecycleMultiplexer completeApplicationLaunchWithFBSScene:transitionContext:] + 104
环境配置
Flutter 3.24.5 Dart 3.5.4. DevTools 2.37.3 pod version: 1.16.2. url_launcher: ^6.3.1 Hardware Model: MacBookPro18,3 Version: 1.0 (1) Code Type: ARM-64 (Native) Role: Foreground Parent Process: launchd_sim [2911] Coalition: com.apple.CoreSimulator.SimDevice.648E4A66-F360-49DA-AD6F-3AC0C3115E9F [1841] Responsible Process: SimulatorTrampoline [2261] OS Version: macOS 15.1.1 (24B91)
解决方向
- 升级CocoaPods版本:当前pod版本1.16.2较旧,和Flutter 3.24.5可能存在兼容性问题,执行
sudo gem install cocoapods升级到最新稳定版 - 更新url_launcher插件:将
url_launcher: ^6.3.1升级到最新版本,修改pubspec.yaml后执行flutter pub get - 清理项目缓存:执行
flutter clean,进入ios目录执行pod deintegrate,再重新执行pod install - 检查插件注册逻辑:确认GeneratedPluginRegistrant是否正确生成,或尝试在AppDelegate中手动注册UrlLauncher插件
- 验证Swift版本兼容性:在Xcode中查看项目的Swift Language Version设置,确保和插件要求的版本一致
内容的提问来源于stack exchange,提问作者vpo

