Hello,
I am currently encountering an issue where SwiftUI View Previews cannot be displayed when the View is defined in a Static Framework target. This issue only occurs under specific conditions.
Environment
-
Xcode: 16.2
-
Scheme Structure:
-
MainApp
-
Test Target: TestHogeFeature
-
Test Setting:
- Gather coverage (Code coverage collection) enabled(all)
-
-
-
Target Structure:
-
MainApp (Application target)
- Dependencies: [HogeFeature, Core]
-
HogeFeature (Static Framework target)
- Dependencies: [Core]
-
Core (Framework target)
- Dependencies: None
-
TestHogeFeature (Unit test target)
- Dependencies: [HogeFeature]
-
Summary
I am currently working on a SwiftUI-based project and have encountered an issue where Previews fail to display under specific conditions. Below are the details:
Issue
In the MainApp scheme, when the code coverage collection setting (Gather coverage for) is enabled, Previews for SwiftUI Views within the HogeFeature (Static Framework) target fail to display correctly. However, the issue is resolved by taking one of the following actions:
- Change HogeFeature from a Static Framework to a Dynamic Framework.
- Remove the build setting
MACH_O_TYPE: staticlib
- Remove the build setting
- Disable the Gather coverage setting in the MainApp scheme.
I have attached the actual error log from the failed Preview.
== DATE: Sunday, January 19, 2025 at 13:13:08 Japan Standard Time 2025-01-19T04:13:08Z == PREVIEW UPDATE ERROR: [Remote] JITError: Runtime linking failure Additional Link Time Errors: Symbols not found: [ ___llvm_profile_runtime ] Symbols not found: [ ___llvm_profile_runtime ] Symbols not found: [ ___llvm_profile_runtime ] ================================== | [Remote] LLVMError | | LLVMError: LLVMError(description: "Failed to materialize symbols: { (static-HogeFeature, { __replacement_tag$1 }) }") == ERROR: [Remote] JITError: Runtime linking failure Additional Link Time Errors: Symbols not found: [ ___llvm_profile_runtime ] Symbols not found: [ ___llvm_profile_runtime ] Symbols not found: [ ___llvm_profile_runtime ] ================================== | [Remote] LLVMError | | LLVMError: LLVMError(description: "Failed to materialize symbols: { (static-HogeFeature, { __replacement_tag$1 }) }") == VERSION INFO: Tools: 16C5032a OS: 24A335 PID: 67797 Model: MacBook Air Arch: arm64e == ENVIRONMENT: openFiles = [ /Users/satoutaichi/work/swift/MultimoduleSampleApp/HogeFeature/HogeView.swift ] wantsNewBuildSystem = true newBuildSystemAvailable = true activeScheme = MainApp activeRunDestination = iPhone 16 Pro variant iphonesimulator arm64 workspaceArena = [x] buildArena = [x] buildableEntries = [ HogeFeature.framework ] runMode = JIT Executor == SELECTED RUN DESTINATION: Simulator - iOS 18.2 | iphonesimulator | arm64 | iPhone 16 Pro | no proxy == EXECUTION MODE OVERRIDES: Workspace JIT mode user setting: true Falling back to Dynamic Replacement: false == PACKAGE RESOLUTION ERRORS: == REFERENCED SOURCE PACKAGES: == JIT LINKAGE: Run Destination: D2AE3E98-6626-45C2-BDF9-0D1E522385E7-iphonesimulator18.2-arm64-iphonesimulator JIT Link Description { 4:HogeFeature.framework } == SESSION GROUP 6749: workspace identifier: WorkspaceIdentifier(identifier: 0D7CE4B3-B7CE-47E6-93E7-BDAFB2675325) providers: [ Preview Provider | Registry-HogeView.swift#1[preview] [Editor(6516)] ] translation units: [ /Users/satoutaichi/work/swift/MultimoduleSampleApp/HogeFeature/HogeView.swift ] attributes: [ Editor(6516): isAppPreviewEnabled: false destinationMode: automatic previewSettings: [ Registry-HogeView.swift#1[preview]: isEnabled: true boxedCanvasControlStates: [] ] ] session: 6754 request sessions: [ Registry[Registry-HogeView.swift#1[preview] (line 45)]: not completed ] == UPDATE SESSION 6754: Start Date: Sunday, January 19, 2025 at 13:12:45 Japan Standard Time Timing { Elapsed Time: 18.833963990211487s a0b72f20dbef2b7e,758952765.224977,18.833963990211487s,,PreviewUpdateSession,id:6754 1f9ab5cf364dfd2e,758952765.438414,0.0008009672164916992s,,MakeBuildGraph, dcf3e3df3578530c,758952765.463143,5.0618369579315186s,,WorkspaceBuild, 12734c8d6c180b5d,758952770.527409,0.20429599285125732s,,AllBuiltTargetDescriptions, e38e02fe7a4612ca,758952770.529021,0.15623092651367188s,,IDEBuiltTargetDescriptionRequest, 519f545ef3760cdb,758952770.686789,0.04451394081115723s,,ProcessBuiltTargetDescription,HogeFeature 9707c7557f701d8,758952771.000517,2.2166930437088013s,,ThunkBuild,HogeView.swift dab44eb1145c2523,758952771.68778,1.8016200065612793s,,AgentLaunch, ca24bee544b65e21,758952773.502084,0.001078963279724121s,,ProductTransfer, } Preview Preflight { UpdaterStore { updaterLimit: single updatersByIdentifier: [ 6766 { state: used RemoteAgentUpdater { workspaceIdentifier: 0D7CE4B3-B7CE-47E6-93E7-BDAFB2675325 supportsOnDevice: true processName: MainApp.app pid: 22675 } } ] expectedAbandonedIdentifiers: [6382, 6572, 6706, 6184, 6616, 6248] } Simulator { platform: iphonesimulator device: 7E431040-2C94-4F31-8795-3984D973F91F iPhone 16 Pro buildNumber: 22C150 runtimePath: /Library/Developer/CoreSimulator/Volumes/iOS_22C150/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 18.2.simruntime } pid: 22675 host bundle: taichi.com.multimoduleSample.MainApp { url: file:///Users/satoutaichi/Library/Developer/Xcode/DerivedData/MultimoduleSample-cskjumppkehsmyhezqqvugiixbki/Build/Products/Debug-iphonesimulator/MainApp.app version: 6759 signingInformation: Code Signing { identifier: taichi.com.multimoduleSample.MainApp hasGetTaskAllow: false isSandboxed: false } attributes: [ AgentRoleKey: Previews, AppExtensionIdentifierPreviewAttributeKey: nil, LaunchConfigArgumentsPreviewAttributesKey: [], AgentCompanionAppBundleIdentifierKey: nil, AgentRunModeKey: JIT Executor, LaunchConfigEnvironmentVariablesPreviewAttributesKey: ["OS_ACTIVITY_TOOLS_PRIVACY": "YES", "PACKAGE_RESOURCE_BUNDLE_PATH": "/Users/satoutaichi/Library/Developer/Xcode/DerivedData/MultimoduleSample-cskjumppkehsmyhezqqvugiixbki/Build/Products/Debug-iphonesimulator", "__XCODE_BUILT_PRODUCTS_DIR_PATHS": "/Users/satoutaichi/Library/Developer/Xcode/DerivedData/MultimoduleSample-cskjumppkehsmyhezqqvugiixbki/Build/Products/Debug-iphonesimulator", "OS_ACTIVITY_TOOLS_OVERSIZE": "YES", "DYLD_INSERT_LIBRARIES": "/Library/Developer/CoreSimulator/Volumes/iOS_22C150/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 18.2.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libLogRedirect.dylib", "SQLITE_ENABLE_THREAD_ASSERTIONS": "1", "TERM": "dumb", "OS_LOG_DT_HOOK_PREFIX": "OSLOG-DDEE723B-4D0C-4C52-953B-D349DCE92927", "__XPC_DYLD_FRAMEWORK_PATH": "/Users/satoutaichi/Library/Developer/Xcode/DerivedData/MultimoduleSample-cskjumppkehsmyhezqqvugiixbki/Build/Products/Debug-iphonesimulator", "IDE_DISABLED_OS_ACTIVITY_DT_MODE": "1", "CFLOG_FORCE_DISABLE_STDERR": "1", "DYLD_LIBRARY_PATH": "/Users/satoutaichi/Library/Developer/Xcode/DerivedData/MultimoduleSample-cskjumppkehsmyhezqqvugiixbki/Build/Products/Debug-iphonesimulator", "__XPC_DYLD_LIBRARY_PATH": "/Users/satoutaichi/Library/Developer/Xcode/DerivedData/MultimoduleSample-cskjumppkehsmyhezqqvugiixbki/Build/Products/Debug-iphonesimulator", "OS_LOG_DT_HOOK_MODE": "0x07", "OS_LOG_TRANSLATE_PRINT_MODE": "0x80", "DYLD_FRAMEWORK_PATH": "/Users/satoutaichi/Library/Developer/Xcode/DerivedData/MultimoduleSample-cskjumppkehsmyhezqqvugiixbki/Build/Products/Debug-iphonesimulator"], ] } builtTargetDescriptions: Build Logs/ResolvedBuiltTargetDescriptions-request-1-taichi.com.multimoduleSample.MainApp.txt } Preview Provider { UpdaterStore { updaterLimit: single updatersByIdentifier: [ 6766 { state: used RemoteAgentUpdater { workspaceIdentifier: 0D7CE4B3-B7CE-47E6-93E7-BDAFB2675325 supportsOnDevice: true processName: MainApp.app pid: 22675 } } ] expectedAbandonedIdentifiers: [6382, 6572, 6706, 6184, 6616, 6248] } Simulator { platform: iphonesimulator device: 7E431040-2C94-4F31-8795-3984D973F91F iPhone 16 Pro buildNumber: 22C150 runtimePath: /Library/Developer/CoreSimulator/Volumes/iOS_22C150/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 18.2.simruntime } pid: 22675 host bundle: taichi.com.multimoduleSample.MainApp { url: file:///Users/satoutaichi/Library/Developer/Xcode/DerivedData/MultimoduleSample-cskjumppkehsmyhezqqvugiixbki/Build/Products/Debug-iphonesimulator/MainApp.app version: 6759 signingInformation: Code Signing { identifier: taichi.com.multimoduleSample.MainApp hasGetTaskAllow: false isSandboxed: false } attributes: [ AgentRoleKey: Previews, AppExtensionIdentifierPreviewAttributeKey: nil, LaunchConfigArgumentsPreviewAttributesKey: [], AgentCompanionAppBundleIdentifierKey: nil, AgentRunModeKey: JIT Executor, LaunchConfigEnvironmentVariablesPreviewAttributesKey: ["OS_ACTIVITY_TOOLS_PRIVACY": "YES", "PACKAGE_RESOURCE_BUNDLE_PATH": "/Users/satoutaichi/Library/Developer/Xcode/DerivedData/MultimoduleSample-cskjumppkehsmyhezqqvugiixbki/Build/Products/Debug-iphonesimulator", "__XCODE_BUILT_PRODUCTS_DIR_PATHS": "/Users/satoutaichi/Library/Developer/Xcode/DerivedData/MultimoduleSample-cskjumppkehsmyhezqqvugiixbki/Build/Products/Debug-iphonesimulator", "OS_ACTIVITY_TOOLS_OVERSIZE": "YES", "DYLD_INSERT_LIBRARIES": "/Library/Developer/CoreSimulator/Volumes/iOS_22C150/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 18.2.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libLogRedirect.dylib", "SQLITE_ENABLE_THREAD_ASSERTIONS": "1", "TERM": "dumb", "OS_LOG_DT_HOOK_PREFIX": "OSLOG-DDEE723B-4D0C-4C52-953B-D349DCE92927", "__XPC_DYLD_FRAMEWORK_PATH": "/Users/satoutaichi/Library/Developer/Xcode/DerivedData/MultimoduleSample-cskjumppkehsmyhezqqvugiixbki/Build/Products/Debug-iphonesimulator", "IDE_DISABLED_OS_ACTIVITY_DT_MODE": "1", "CFLOG_FORCE_DISABLE_STDERR": "1", "DYLD_LIBRARY_PATH": "/Users/satoutaichi/Library/Developer/Xcode/DerivedData/MultimoduleSample-cskjumppkehsmyhezqqvugiixbki/Build/Products/Debug-iphonesimulator", "__XPC_DYLD_LIBRARY_PATH": "/Users/satoutaichi/Library/Developer/Xcode/DerivedData/MultimoduleSample-cskjumppkehsmyhezqqvugiixbki/Build/Products/Debug-iphonesimulator", "OS_LOG_DT_HOOK_MODE": "0x07", "OS_LOG_TRANSLATE_PRINT_MODE": "0x80", "DYLD_FRAMEWORK_PATH": "/Users/satoutaichi/Library/Developer/Xcode/DerivedData/MultimoduleSample-cskjumppkehsmyhezqqvugiixbki/Build/Products/Debug-iphonesimulator"], ] } builtTargetDescriptions: Build Logs/ResolvedBuiltTargetDescriptions-request-2-taichi.com.multimoduleSample.MainApp.txt } Build Graph { MainApp.app (#5) Core.framework (#1) HogeFeature.framework (#4) Core.framework (#1) sourceFile(file:///Users/satoutaichi/work/swift/MultimoduleSampleApp/HogeFeature/HogeView.swift -> HogeView.swift) (#2) HogeView.swift (#3) } Update Plan { iOS [arm64 iphonesimulator18.2 iphonesimulator] (iPhone 16 Pro, D2AE3E98-6626-45C2-BDF9-0D1E522385E7-iphonesimulator18.2-arm64-iphonesimulator), [], thinning disabled, thunking enabled) { Destination: iPhone 16 Pro D2AE3E98-6626-45C2-BDF9-0D1E522385E7 | default device for iphonesimulator [ MainApp app - Previews { execution point packs [ [source: HogeView.swift, role: Previews] (in HogeFeature) ] translation units [ HogeView.swift (in HogeFeature.framework) ] modules [ Core.framework HogeFeature.framework MainApp.app ] jit link description [ HogeFeature.framework ] } ] } } == POWER STATE LOGS: 2025/01/19, 13:11 Received power source state: Battery Powered (lowPowerMode: true, status: unplugged, level: 75%) 2025/01/19, 13:11 Broadcasting device power state: Low Power 2025/01/19, 13:11 No device power state user override user default value. 2025/01/19, 13:12 Received power source state: Battery Powered (lowPowerMode: true, status: unplugged, level: 74%)Current power state: Low Power
Questions
- Why does this issue occur only when using a Static Framework with code coverage enabled?
- Is there any way to resolve this issue while maintaining the current configuration (Static Framework with code coverage enabled)?
I would appreciate any advice or insights regarding the cause and potential solutions.