Failed to preview iOS app due to RealityKitContent.rkassets (should be linked only on visionOS)

Hello!

My app supports iOS and visionOS in a single target. But when I preview the app on iOS device/simulator, an error occurred:

The RealityKitContent.rkassets is located in my RealityKitContent package that is linked on visionOS.

It seems that Xcode Preview is ignoring the link settings and attempt to build RealityKitContent.rkassets on iOS.


Reproduce Steps:

  1. Clone my demo project at https://github.com/gongzhang/rkassets-preview-issue-demo
  2. Build the app for iOS (success)
  3. Preview ContentView.swift (failed due to RealityKitContent.rkassets issue)

Hello,

Thank you for providing that demo project, very useful!

The reason you are seeing this error is because one of your #if os(visionOS) is failing:

import SwiftUI
#if os(visionOS)
import RealityKit
import RealityKitContent
#endif

For some reason, the compiler is failing to properly acknowledge this conditional compilation block, simply adding an empty line worked around the issue for me:

import SwiftUI

#if os(visionOS)
import RealityKit
import RealityKitContent
#endif

Please do file a bug report for this issue using [Feedback Assistant]<https://developer.apple.com/bug-reporting/>!

@gchiste 😄 Thanks! You are fast. Which Xcode version are you using? I'm on Xcode 15.0 beta 8 (15A5229m) but I can workaround the issue by adding an empty line or removing the import statement.

Hi,

Sorry to hear you are having problems getting previews working for your multi platform target. I believe you are hitting a known issue with previews not respecting the platform filter on the linkages, but to know for sure we'd need you to file a feedback with diagnostics so we can take a look.

Steps to generate helpful diagnostics:

  1. Download and install the logging profile on all devices involved. Instructions and profiles are available here: https://developer.apple.com/bug-reporting/profiles-and-logs/?name=swift
  2. Reproduce the issue
  3. Click the "Diagnostics" button in the error banner in Previews' Canvas area (or if the banner is missing you can use the menu: Editor > Canvas > Diagnostics)
  4. In the sheet that appears, click "Generate Report" in the bottom left of the sheet
  5. Attach (or make from the folder) the resulting zip file to the bug (will be named something like previews-diagnostics-0123456789.zip)
  6. Generate the sysdiagnose(s) and attach those too

If you are indeed hitting the known issue then a workaround you can try is to have a separate target per platform.

Failed to preview iOS app due to RealityKitContent.rkassets (should be linked only on visionOS)
 
 
Q