iOS Build Environment Help Center

Cannot build because of Swift language

append delete Cemil Oten

Hello,

We are unable to build for iOS because of this error:
*your project contains code written in the Swift language, but the Swift compiler hasn't been ported to Windows yet.*

When we try adding custom frameworks to either MainApp or UnityFramework, it is not detected in the build process:
*Building the dependency project UnityFramework...
+ Preparing output directory...
+ XCFrameworks: 0 supplied
+ Libraries: 5 supplied, 0 built
+ Frameworks: 0 supplied, 0 built*

We used frameworks from this page
https://github.com/facebook/facebook-ios-sdk/releases

Our XCode project is built with a Unity project that already contains a Facebook SDK (the latest) and we cannot remove it because it comes from a third party with tons of other functionalities.

What are we doing wrong and how can we fix this?

Thank you,
Cemil

Reply RSS

Replies

append delete #1. Pierre-Marie Baty

Hello

The Swift code is typically in the Facebook SDK source code, and you encounter that when you use CocoaPods to layout the Facebook SDK source code and compile it altogether with your project. But there's a better way to do it where you don't encounter this problem.

If you use the pre-compiled Facebook frameworks (the release labeled "static" or "dynamic") you don't need to compile that Swift code yourself as it's already been compiled into the Facebook framework, all you need to do is to supply the missing frameworks your project needs to the linker through the "Add extra framework" buttons (and of course, make the appropriate Info.plist changes as documented by Facebook).

There are a couple threads on this forum that illustrate how to link with pre-compiled frameworks. The process is similar for whichever SDK your project uses (Facebook, Google, etc).

Let me know if you need more help.

append delete #2. Bassel_l

Hello, I've injected the framework by using the "Add extra framework" but it is still reporting that I have code written in swift that can't be compiled in Libraries\FacebookSDK\SDK\Editor\iOS\Swift

append delete #3. Bassel_l

I also removed them from the Podfile so that they'll not be installed with Cocoapods

append delete #4. Pierre-Marie Baty

Hello

Well, I wasn't yet aware that there could be Swift files in a Xcode project that the Unity editor generates itself, so that could be a first timer.

Could you please send me your project (or a stripped version of it that still demonstrates the problem) so that I see what to do ? Confidentiality is guaranteed.

You can e.g. upload it on an online storage space and send the link to my email address (pm at this domain dot com).

If your project is buildable I'll tell you how to do it, and if it's not I'll fix what's needed so that it is.

Thanks in advance

:: @Pierre-Marie Baty added on 12 Sep ’22 · 17:14

*edit* IMPORTANT: make sure it's a fresh, untouched Xcode project just created by the Unity editor (i.e. delete the Xcode project directory thoroughly, and have Unity create it again).

append delete #5. MenionLeah

Facing the same issue: did you ever find a solution to it?

It looks like from version 13.2.0 onward (https://developers.facebook.com/docs/unity/downloads/), Facebook SDK introduced some swift files in the .unitypackage file:
SDK\Editor\iOS\Swift
- FBSDKShareTournamentDialog.swift
- FBSDKTournament.swift
- FBSDKTournamentFetcher.swift
- FBSDKTournamentUpdater.swift

I spent a couple of days over it without being able to find a solution (and upgrading is a must, since older versions don't work on Android 13 anymore)

append delete #6. Pierre-Marie Baty

Unfortunately I have no workaround at the moment.

Integrating Swift has become a priority but unfortunately I have another task to fulfill (paid contract) that will keep me busy until end of January.

In the meantime perhaps the people who developed the Facebook SDK for Unity could be contacted and be asked to rewrite these 4 files in Objective-C ? It shouldn't be a daunting job.

I promise to address this problem as soon as I have the possibility. Currently what I lack is a way to drive the Swift compiler to produce cross-compiled object files (ie the Swift compiler knows it runs on a Windows/Intel platform, but I want it to compile object files that will be linked for an Apple/arm64 platform). I know how to do that with clang, I haven't found how to do that with swiftc. Maybe the possibility already exists, but there doesn't seem to be many people out here doing it and I can't find that documented anywhere. If anyone has a clue...

append delete #7. MenionLeah

I asked them by opening a new issue on Git; I won't be so optimistic, though:
- it looks like they're putting more and more effort on swift
- their SDK is well known for having TERRIBLE support, QA and overall quality

append delete #8. Fraccas

Hi Pierre-Marie,

Any updates here? I'm having the same issue as the users with the swift files included with the Unity Facebook SDK.

- FBSDKShareTournamentDialog.swift
- FBSDKTournament.swift
- FBSDKTournamentFetcher.swift
- FBSDKTournamentUpdater.swift

I've happily used your product for years but if there's no solution I'll need to purchase a Mac to build to iOS, unfortunately.

append delete #9. Pierre-Marie Baty

Hello Fraccas

I understand this (compiling mixed-source targets) is the most urgent problem to solve for many users. Alas, I have other activities of counseling and development and I'm currently poised with a customer with so much needs that it leaves me with very little free time, and this situation will last until january. It's twice more unfortunate, because I *know* how to implement what's needed to build mixed-sources projects (now that the Swift compiler works), but I just don't have enough time to achieve it. I have just enough free time to handle the other simpler requests.

If you can't wait til january, and buying a used Mac (but recent enough to support the latest iOS SDK) is within your budget, I'm afraid it's the safest thing to do for you now.

The alternative for you is to not use the master build script and implement your own scripted logic for building your project, using the builder's tools. Everything is here, it's just a matter of doing things slightly differently. Basically you need to "swap" compiler-produced source layout files at the right time when you build mixed-source projects. The Objective-C part of the module needs to be exposed to the Swift compiler when building the Swift files, and the Swift part of the module needs to be exposed to the Objective-C compiler when building the Objective-C files. It's kind of a chicken-and-egg problem ; and to solve it 3 passes are necessary, 2 for producing the interface definition files, the actual build being done in the third. Have a look at Jordan Rose's reply here: https://forums.swift.org/t/how-apple-sdk-overlays-work/11317/2, and of course https://github.com/apple/swift/blob/main/docs/Driver.md - beware, if you're not quite experienced with all this, it might be hard for your to understand what it's all about - and what you need to do to make it work.

append delete #10. Fraccas

Hi Pierre-Marie,

Thanks for the information!

I bought a cheap $200 used Mac today and was able to upload my app to the App Store. I actually prefer deploying from Windows with your tool so I'll keep an eye on the update you spoke up hopefully coming in January.

I've been using your tool since 2019 and have definitely got great value out of this product. Looking forward to coming back once the new update is published!

Reply

(Leave this as-is, it’s a trap!)

There is no need to “register”, just enter the same name + password of your choice every time.

Pro tip: Use markup to add links, quotes and more.

Moderators: Pierre-Marie Baty