Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Fatal Crash on Launch: SwiftUICore Library Not Loaded When Using Capacitor 6 with Xcode 16 on iOS 17 and Below #7667

Closed
1 of 3 tasks
Jaxter2017 opened this issue Sep 19, 2024 · 3 comments

Comments

@Jaxter2017
Copy link

Capacitor Version

Latest Dependencies:

@capacitor/cli: 6.1.2
@capacitor/core: 6.1.2
@capacitor/android: 6.1.2
@capacitor/ios: 6.1.2

Installed Dependencies:

@capacitor/android: not installed
@capacitor/cli: 6.1.2
@capacitor/core: 6.1.2
@capacitor/ios: 6.1.2

Other API Details

- **Xcode Version:** 16
- **iOS Versions Affected:** 17 and below
- **SwiftUI Components Involved:** `UIViewRepresentable`, others requiring `SwiftUICore`
- **SwiftUICore Framework:** Introduced in iOS 18, not present in earlier iOS versions.

### API and Tooling Versions

- **npm Version:** 9.5.1
- **Node.js Version:** v18.16.0
- **CocoaPods Version:** 1.15.2 (although same bug occurs when using SPM Capacitor v6 with `npx cap add ios --packagemanager SPM`)

Platforms Affected

  • iOS
  • Android
  • Web

Current Behavior

In a moderately intricate SwiftUI application using Capacitor version 6 with Xcode version 16, the app crashes on launch when deployed to devices running iOS 17 and below. The crash occurs due to the application attempting to load the SwiftUICore library, which is only available starting from iOS 18. Specifically, certain SwiftUI components, such as UIViewRepresentable, trigger this crash by relying on SwiftUICore. This behavior is demonstrated in the provided minimal reproducible repository, where the use of UIViewRepresentable leads to the fatal crash immediately upon launch. Other SPM packages like exyte/SVGView also cause this crash.

Note: SwiftUICore is a new framework introduced by Apple in iOS 18 and was not present in earlier iOS versions.

Expected Behavior

Xcode 16 should recognize that the SwiftUICore library is only available starting from iOS 18 and handle applications targeting iOS 17 and below appropriately. The app should not crash on launch due to the absence of SwiftUICore, and instead, the build process should either provide fallback functionality or omit the dependency as needed.

While this issue might point to a bug within Xcode 16, it appears to be specifically triggered when using Capacitor 6. I have not been able to reproduce this bug in fresh Swift projects that do not involve Capacitor. The issue only arises when Capacitor is involved, indicating that Capacitor may be influencing or exacerbating the problem in some way.

Project Reproduction

https://github.com/Jaxter2017/swiftui_xcode16_bug

Additional Information

To temporarily mitigate this issue, you can adjust the build settings of your project to weakly link the SwiftUICore library. This allows the app to run without a strict connection to the library, preventing the crash on iOS versions where SwiftUICore is unavailable.

Add -weak_framework SwiftUICore to the Other Linker Flags (OTHER_LDFLAGS) section of the Build Settings tab of your app target.

@netural-philipp-gabriel
Copy link

netural-philipp-gabriel commented Sep 30, 2024

Yikes, this is actually bad. We are experiencing the same problem.

I wonder if the app also crashes, if you'd archive and upload an app with Xcode 16 and users with iOS 17 download it directly from the store.

Thanks for the workaround @Jaxter2017.

@jcesarmobile
Copy link
Member

jcesarmobile commented Oct 1, 2024

This is an Apple/Xcode bug, as you might have seen in https://forums.developer.apple.com/forums/thread/757397

There seem to be some naming conflict when calling the scheme App as Capacitor apps do.

You can rename the scheme if you want by following this instructions https://capacitorjs.com/docs/v5/ios/configuration#renaming-your-app

We also noticed that this is only a problem for debug builds, if you build for release the app doesn't crash.

@jcesarmobile jcesarmobile closed this as not planned Won't fix, can't repro, duplicate, stale Oct 1, 2024
@ionitron-bot ionitron-bot bot removed the triage label Oct 1, 2024
@netural-philipp-gabriel
Copy link

@jcesarmobile Is it really a known Apple bug? Has someone filed a feedback for it already?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants