关于 Xcode 16.2 开发小组件在 iOS14-15 不显示小组件

1,689 阅读8分钟

最近在用 Xcode 16.2 开发小组件,在 iOS17.5 模拟器小组件一切正常,但在 iOS 15.2 模拟器却怎么都找不到小组件,找遍了百度和Google都没找到解决方案,最终总算在苹果开发者社区找到了思路。

一般情况 Xcode 16+ 才会有这个问题,苹果开发者社区有苹果的工程师说正在修复中,但我现在找不到那篇帖子了...

国外有很多开发者遇到了这个问题,但不知道为什么国内好像完全找不到开发者提过这个问题

image.png

截止现在,解决方案就是将 Xcode 降级回 Xcode 15.4,其中也有些坑,下面是具体的步骤。

1. 安装 Xcode 15.4

1.1 官网下载 Xcode 15.4

地址:developer.apple.com/download/al…

下载:Xcode 15.4

image.png

1.2 在保留 Xcode 16.2 的基础上安装 Xcode 15.4

将下载的 Xcode_15.4.xip 双击解压,会得到一个 Xcode 应用,可以把这个应用放在特定目录,或直接放在 Mac 的应用程序下,并命名为 Xcode-15.4,我是直接放在应用程序里。

image.png

1.3 通过指令切换 Xcode 版本

切换到15.4:sudo xcode-select -s /Applications/Xcode-15.4.app/Contents/Developer

切换到16.2:sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

查看当前 Xcode 版本:xcodebuild -version

image.png

2. 原项目(flutter)跑不起来了?

Xcode 15.4 安装好了,现在新问题来了,我的项目跑不起来了(不确定别人的项目能不能直接运行,放在我切换版本后项目跑不起来了),其实就是 ios/Runner.xcodeproj/project.pbxproj 文件配置有问题,但我没找到具体是哪里有问题。

存在两个问题:

  1. 执行 open ios/Runner.xcodeproj 打开 Xcode 时, Xcode 闪退
  2. 执行 flutter run 时报错
ProcessException: Process exited abnormally with exit code -6:
Command line invocation:
    /Applications/Xcode-15.4.app/Contents/Developer/usr/bin/xcodebuild -list

User defaults from command line:
    IDEPackageSupportUseBuiltinSCM = YES


2024-12-23 13:06:27.542 xcodebuild[70820:19190217] [MT] DVTAssertions: ASSERTION FAILURE in
DevToolsCore/Xcode3Core/LegacyProjects/Frameworks/DevToolsCore/DevToolsCore/ProjectModel/DataModel/References/SynchronizedGroups/PBXFileSystemSynchronizedAbstractGroup.m:28
Details:  Assertion failed: IDEFileSystemSynchronizedGroupsAreEnabled()
Object:   <PBXFileSystemSynchronizedRootGroup>
Method:   +allocWithZone:
Thread:   <_NSMainThread: 0x12800fa50>{number = 1, name = main}
Hints: 

Backtrace:
  0   -[DVTAssertionHandler handleFailureInMethod:object:fileName:lineNumber:assertionSignature:messageFormat:arguments:] (in DVTFoundation)
  1   _DVTAssertionHandler (in DVTFoundation)
  2   _DVTAssertionFailureHandler (in DVTFoundation)
  3   _DVTAssertionWarningHandler (in DVTFoundation)
  4   -[PBXFileSystemSynchronizedAbstractGroup initWithName:path:sourceTree:] (in DevToolsCore)
  5   -[PBXPListUnarchiver _unarchiveObjectWithGlobalIDHexString:] (in DevToolsCore)
  6   -[PBXPListUnarchiver _decodeMutableObjectArrayFromPListArray:] (in DevToolsCore)
  7   -[PBXPListUnarchiver decodeMutableObjectArrayForKey:] (in DevToolsCore)
  8   -[PBXUnarchivingBinding readValueForObject:fromPListUnarchiver:] (in DevToolsCore)
  9   -[PBXObject _unarchiveValuesForArchiveMask:fromPListUnarchiver:] (in DevToolsCore)
 10   -[PBXObject readFromPListUnarchiver:] (in DevToolsCore)
 11   -[PBXReference readFromPListUnarchiver:] (in DevToolsCore)
 12   -[PBXPListUnarchiver _unarchiveObjectWithGlobalIDHexString:] (in DevToolsCore)
 13   -[PBXPListUnarchiver decodeObjectForKey:] (in DevToolsCore)
 14   -[PBXUnarchivingBinding readValueForObject:fromPListUnarchiver:] (in DevToolsCore)
 15   -[PBXObject _unarchiveValuesForArchiveMask:fromPListUnarchiver:] (in DevToolsCore)
 16   -[PBXObject readFromPListUnarchiver:] (in DevToolsCore)
 17   -[PBXContainer readFromPListUnarchiver:] (in DevToolsCore)
 18   -[PBXProject readFromPListUnarchiver:] (in DevToolsCore)
 19   -[PBXPListUnarchiver _unarchiveObjectWithGlobalIDHexString:] (in DevToolsCore)
 20   -[PBXPListUnarchiver decodeRootObject] (in DevToolsCore)
 21   +[PBXProject projectWithFile:errorHandler:readOnly:] (in DevToolsCore)
 22   -[Xcode3Project initWithFilePath:extension:workspace:options:error:] (in DevToolsCore)
 23   __82+[IDEContainer _retainedContainerAtFilePath:fileDataType:workspace:options:error:]_block_invoke_2 (in IDEFoundation)
 24   _dispatch_client_callout (in libdispatch.dylib)
 25   _dispatch_lane_barrier_sync_invoke_and_complete (in libdispatch.dylib)
 26   DVTDispatchBarrierSync (in DVTFoundation)
 27   -[DVTDispatchLock performLockedBlock:] (in DVTFoundation)
 28   __82+[IDEContainer _retainedContainerAtFilePath:fileDataType:workspace:options:error:]_block_invoke (in IDEFoundation)
 29   __58-[DVTModelObjectGraph performBlockCoalescingModelChanges:]_block_invoke (in DVTFoundation)
 30   -[DVTModelGraphTransactionScope performTransaction:] (in DVTFoundation)
 31   -[DVTModelObjectGraph performBlockCoalescingModelChanges:] (in DVTFoundation)
 32   +[IDEContainer _retainedContainerAtFilePath:fileDataType:workspace:options:error:] (in IDEFoundation)
 33   -[IDEWorkspace _configureWrappedWorkspaceWithError:] (in IDEFoundation)
 34   __82+[IDEContainer _retainedContainerAtFilePath:fileDataType:workspace:options:error:]_block_invoke (in IDEFoundation)
 35   +[IDEContainer _retainedContainerAtFilePath:fileDataType:workspace:options:error:] (in IDEFoundation)
 36   +[IDEContainer retainedWrappedWorkspaceForContainerAtFilePath:fileDataType:error:] (in IDEFoundation)
 37   -[Xcode3CommandLineBuildTool _resolveInputOptionsWithTimingSection:] (in Xcode3Core)
 38   -[Xcode3CommandLineBuildTool run] (in Xcode3Core)
 39   XcodeBuildMain (in libxcodebuildLoader.dylib)
 40   -[XcodebuildPreIDEHandler loadXcode3ProjectSupportAndRunXcode3CommandLineBuildToolWithArguments:] (in xcodebuild)
 41   -[XcodebuildPreIDEHandler runWithArguments:] (in xcodebuild)
 42   main (in xcodebuild)
 43   start (in dyld)
  Command: /usr/bin/arch -arm64e xcrun xcodebuild -list

2.1 判断 Xcode 15.4 是否安装正确

方法一:

flutter create test 新建一个新的 flutter 项目,看看能不能正常运行,并且能够通过 Xcode 打开,如果可以,则可以继续下一步

方法二:

直接用 Xcode 15.4 创建一个空白项目,如果能正常运行,则说明安装正确

2.2 解决方案

  1. 备份项目根目录下的 ios 目录
  2. 删除项目根目录下的 ios 目录
  3. 重新生成 ios 目录,执行 flutter create .
  4. 重新生成 ios 目录后会重新生成 bundle identifier,建议全局新生成的 bundle identifier,替换成以前的,不然运行项目会报错
  5. 尝试运行 flutter run,第一次运行时可能会报错,没关系,再运行一次就行了
Error (Xcode): Building for 'iOS-simulator', but linking in object file (/Applications/xxxx/ios/Pods/ZXSDK/ZXSDK.framework/ZXSDK[arm64][3](ZXSDKTcpSessionManager.o)) built for 'iOS'
Error (Xcode): Linker command failed with exit code 1 (use -v to see invocation)
Could not build the application for the simulator.
Error launching application on iPhone 13 Pro.
  1. 正常情况下就能成功运行 flutter 项目了,如果能正常运行了,则可以恢复iOS的配置了(注意:这个时候别恢复 project.pbxproj 和小组件代码!!)
  2. 项目正常运行后再添加空白小组件,小组件名称和配置按照以前的来配置(命名、app group 等)

一般情况会报错:

Error (Xcode): Cycle inside Runner; building could produce unreliable results.
Cycle details:
→ That command depends on command in Target 'Runner': script phase “[CP] Embed Pods Frameworks”
○ Target 'Runner'
○ That command depends on command in Target 'Runner': script phase “Thin Binary”
○ Target 'Runner' has process command with output '/Applications/xxx/build/ios/Debug-iphonesimulator/Runner.app/Info.plist'
○ Target 'Runner' has copy command from '/Applications/xxx/build/ios/Debug-iphonesimulator/GoldStatisticsWidgetExtension.appex' to
'/Applications/xxx/build/ios/Debug-iphonesimulator/Runner.app/PlugIns/GoldStatisticsWidgetExtension.appex'
○ That command depends on command in Target 'Runner': script phase “[CP] Copy Pods Resources”
○ Target 'Runner'


Raw dependency cycle trace:

target:  ->

node: <all> ->

command: <all> ->

node: /Applications/xxx/build/ios/Debug-iphonesimulator/Runner.app/_CodeSignature ->

command: P0:target-Runner-18c1723432283e0cc55f10a6dcfd9e0288a783a885d8b0b3beb2e9f90bde3f49-:Debug:CodeSign
/Applications/xxx/build/ios/Debug-iphonesimulator/Runner.app ->

node: /Applications/xxx/build/ios/Debug-iphonesimulator/Runner.app/Frameworks/MTBBarcodeScanner.framework/ ->

directoryTreeSignature: } ->

directoryContents: /Applications/xxx/build/ios/Debug-iphonesimulator/Runner.app/Frameworks/MTBBarcodeScanner.framework ->

CYCLE POINT ->

node: /Applications/xxx/build/ios/Debug-iphonesimulator/Runner.app/Frameworks/MTBBarcodeScanner.framework ->

command: P2:target-Runner-18c1723432283e0cc55f10a6dcfd9e0288a783a885d8b0b3beb2e9f90bde3f49-:Debug:PhaseScriptExecution [CP] Embed Pods Frameworks
/Users/huasonglin/Library/Developer/Xcode/DerivedData/Runner-boutaagkxdqvsudyjujbixiwquit/Build/Intermediates.noindex/Runner.build/Debug-iphonesimulator/Runner.buil
d/Script-8A940D512DFEAEA305376EAA.sh ->

node:
/Users/huasonglin/Library/Developer/Xcode/DerivedData/Runner-boutaagkxdqvsudyjujbixiwquit/Build/Intermediates.noindex/Runner.build/Debug-iphonesimulator/Runner.buil
d/InputFileList-8A940D512DFEAEA305376EAA-Pods-Runner-frameworks-Debug-input-files-0e33b0ae31be6888f6074c90212e344b-resolved.xcfilelist ->

command: P2:target-Runner-18c1723432283e0cc55f10a6dcfd9e0288a783a885d8b0b3beb2e9f90bde3f49-:Debug:WriteAuxiliaryFile
/Users/huasonglin/Library/Developer/Xcode/DerivedData/Runner-boutaagkxdqvsudyjujbixiwquit/Build/Intermediates.noindex/Runner.build/Debug-iphonesimulator/Runner.buil
d/InputFileList-8A940D512DFEAEA305376EAA-Pods-Runner-frameworks-Debug-input-files-0e33b0ae31be6888f6074c90212e344b-resolved.xcfilelist ->

node: <target-Runner-18c1723432283e0cc55f10a6dcfd9e0288a783a885d8b0b3beb2e9f90bde3f49--fused-phase4-thin-binary> ->

command: P0:::Gate target-Runner-18c1723432283e0cc55f10a6dcfd9e0288a783a885d8b0b3beb2e9f90bde3f49--fused-phase4-thin-binary ->

node:
<execute-shell-script-18c1723432283e0cc55f10a6dcfd9e02f1eee2015e8ff5ebcd27678f788c2826-target-Runner-18c1723432283e0cc55f10a6dcfd9e0288a783a885d8b0b3beb2e9f90bde3f4
9-> ->

command: P2:target-Runner-18c1723432283e0cc55f10a6dcfd9e0288a783a885d8b0b3beb2e9f90bde3f49-:Debug:PhaseScriptExecution Thin Binary
/Users/huasonglin/Library/Developer/Xcode/DerivedData/Runner-boutaagkxdqvsudyjujbixiwquit/Build/Intermediates.noindex/Runner.build/Debug-iphonesimulator/Runner.buil
d/Script-3B06AD1E1E4923F5004D2608.sh ->

node: /Applications/xxx/build/ios/Debug-iphonesimulator/Runner.app/Info.plist/ ->

directoryTreeSignature: a ->

directoryContents: /Applications/xxx/build/ios/Debug-iphonesimulator/Runner.app/Info.plist ->

node: /Applications/xxx/build/ios/Debug-iphonesimulator/Runner.app/Info.plist ->

command: P0:target-Runner-18c1723432283e0cc55f10a6dcfd9e0288a783a885d8b0b3beb2e9f90bde3f49-:Debug:ProcessInfoPlistFile
/Applications/xxx/build/ios/Debug-iphonesimulator/Runner.app/Info.plist /Applications/xxx/ios/Runner/Info.plist
->

node: /Applications/xxx/build/ios/Debug-iphonesimulator/Runner.app/PlugIns/GoldStatisticsWidgetExtension.appex ->

command: P0:target-Runner-18c1723432283e0cc55f10a6dcfd9e0288a783a885d8b0b3beb2e9f90bde3f49-:Debug:Copy
/Applications/xxx/build/ios/Debug-iphonesimulator/Runner.app/PlugIns/GoldStatisticsWidgetExtension.appex
/Applications/xxx/build/ios/Debug-iphonesimulator/GoldStatisticsWidgetExtension.appex ->

node: <target-Runner-18c1723432283e0cc55f10a6dcfd9e0288a783a885d8b0b3beb2e9f90bde3f49--fused-phase6--cp--copy-pods-resources> ->

command: P0:::Gate target-Runner-18c1723432283e0cc55f10a6dcfd9e0288a783a885d8b0b3beb2e9f90bde3f49--fused-phase6--cp--copy-pods-resources ->

node: /Applications/xxx/build/ios/Debug-iphonesimulator/Runner.app/fluwx_privacy.bundle ->

command: P2:target-Runner-18c1723432283e0cc55f10a6dcfd9e0288a783a885d8b0b3beb2e9f90bde3f49-:Debug:PhaseScriptExecution [CP] Copy Pods Resources
/Users/huasonglin/Library/Developer/Xcode/DerivedData/Runner-boutaagkxdqvsudyjujbixiwquit/Build/Intermediates.noindex/Runner.build/Debug-iphonesimulator/Runner.buil
d/Script-E81C299A0BC0FF032C1949E3.sh ->

node:
/Users/huasonglin/Library/Developer/Xcode/DerivedData/Runner-boutaagkxdqvsudyjujbixiwquit/Build/Intermediates.noindex/Runner.build/Debug-iphonesimulator/Runner.buil
d/InputFileList-E81C299A0BC0FF032C1949E3-Pods-Runner-resources-Debug-input-files-79a01d4b271c4fb1457562b9258ddb89-resolved.xcfilelist ->

command: P2:target-Runner-18c1723432283e0cc55f10a6dcfd9e0288a783a885d8b0b3beb2e9f90bde3f49-:Debug:WriteAuxiliaryFile
/Users/huasonglin/Library/Developer/Xcode/DerivedData/Runner-boutaagkxdqvsudyjujbixiwquit/Build/Intermediates.noindex/Runner.build/Debug-iphonesimulator/Runner.buil
d/InputFileList-E81C299A0BC0FF032C1949E3-Pods-Runner-resources-Debug-input-files-79a01d4b271c4fb1457562b9258ddb89-resolved.xcfilelist ->

node: <target-Runner-18c1723432283e0cc55f10a6dcfd9e0288a783a885d8b0b3beb2e9f90bde3f49--fused-phase5--cp--embed-pods-frameworks> ->

command: P0:::Gate target-Runner-18c1723432283e0cc55f10a6dcfd9e0288a783a885d8b0b3beb2e9f90bde3f49--fused-phase5--cp--embed-pods-frameworks ->

node: /Applications/xxx/build/ios/Debug-iphonesimulator/Runner.app/Frameworks/MTBBarcodeScanner.framework

Could not build the application for the simulator.
Error launching application on iPhone 13 Pro.

在 Xcode 中配置一下 RunnerBuild Phases,将 Embed Foundation Extensions 移动到 Run Script 前面即可:

image.png

正常情况执行 flutter run 就能运行项目,并且能够在 iOS 14、15 找到小组件了,然后再把原项目的小组件代码恢复即可。

3. 其他问题

3.1 运行没报错,但在模拟器找不到小组件

检查一下 Runner -> Targets -> 小组件Minimum DeploymentsBuild Settings 里面的 iOS Deployment Target iOS 版本是不是设置太高了,如果设置太高了,则低于改版本的iOS系统会找不到小组件。

image.png

image.png