How to Build a Swift Package for iOS Over Command Line

How can I build a Swift Package for iOS over command line?

At time of writing (Feb 16, 2019), a working solution is:

swift build -v \
-Xswiftc "-sdk" \
-Xswiftc "`xcrun --sdk iphonesimulator --show-sdk-path`" \
-Xswiftc "-target" \
-Xswiftc "x86_64-apple-ios13.0-simulator"

This command uses -Xswiftc to workaround the issue by overriding the sdk from macOS to iphonesimulator.

Strictly we add these flags so developers can work around issues, but they also should report a bug so that we can provide a proper solution for their needs.

Source

So I'm guessing there will be a more elegant solution in the future.

How do you build iOS specific packages using SPM?

I "solved" this by wrapping all my files in #if !os(macOS) #endif blocks. So the package builds on a Mac, but it doesn't have any content.

How to use Swift Package Manager(SPM) in cli?


I have followed those steps to solve the problem.

  1. set git HTTP proxy
git config --global http.proxy http://0.0.0.0:1087
git config --global http.proxy socks5://0.0.0.0:1080

  1. set ssh proxy for host

Append those lines at the end of ~/.ssh/config to add a socks5 proxy

Host github.com
ProxyCommand nc -X 5 -x 0.0.0.0:1080 %h %p

  1. use xcodebuild command to resolve package dependencies

Remember you must add the -scmProvider system option to force xcodebuild to use system git and git configurations, or it will use the xcode built-in git which will never go through the proxy.

xcodebuild -resolvePackageDependencies -scmProvider system

Some references here:

  • Building Swift Packages or Apps that Use Them in Continuous Integration Workflows

How to create and build a swift package

UIKit is a framework in iOS and won't be accessible.

#if canImport(UIKit)

// Code specific to platforms where UIKit is available

#endif

Related:

  • Creating a Swift Package with Xcode

Build error when adding a dependency using Swift Package Manager in Xcode for a Flutter project

I think I might have the fix for you.

Please close your workspace in XCode, and go back and open the .xcodeproj file INSTEAD of the .xcworkspace file.

(/yourApp/ios/Runner.xcodeproj most likely)

When the project is open, in XCode menu bar click File -> Project Settings -> Advanced.

Change the option from LEGACY to XCODE DEFAULT.

Now open the .xcworkspace again and it should work!



Related Topics



Leave a reply



Submit