Swift toolchain for android on macos
- You are on arm64 mac
- Recent xcode vetsion installed on mac
- Install NDK and CMake. Instructions
Here are steps to compile package
$ export PATH="<toolchain_path>/usr/bin:$PATH"
$ export SWIFT_EXEC_MANIFEST=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc
export SWIFT_EXEC=<toolchain_path>/usr/bin/swiftc-android
andswiftc-android
should be executablecd <package_path>
swift build --triple aarch64-unknown-linux-android \
--emit-swift-module-separately \
--sdk <toolchain_path> \
--toolchain <toolchain_path>/usr/bin \
-Xswiftc -emit-library \
-Xswiftc -emit-module \
-Xcc -I/Users/$USER/Library/Android/sdk/ndk/25.1.8937393/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include \
-Xcc -I/Users/$USER/Library/Android/sdk/ndk/25.1.8937393/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/aarch64-linux-android \
-v
$ swift run SwiftBuilder \
--working-folder <WORKING_FOLDER> \
--android-sdk <PATH_TO_ANDROID_SDK> \
--source-root "$PWD"
For example, values might be:
- WORKING_FOLDER -
~/ws/SwiftAndroid
, this should be empty folder, which will be used by app for checkout and build - PATH_TO_ANDROID_SDK -
~/Library/Android/sdk/
, inside we expect ndk fodler with NDK v25
To modify some constants:
- NDK version in
HostConfig/NDK.swift
- Android API level in
AndroidConfig/AndroidAPILevel.swift
- To change macOS target, like arch or min deployment target - check
HostConfig/MacOS.swift
While building, we will save progress with completed steps in current-progress.json
.
This helps us avoid re-running long build operations, if we encountered any problem.
If you want start from scratch - just delete file from working folder. Alternatively, you can manually remove steps, which you want to repeat.
- Find new release tag in github repo
- Follow steps here to update default checkout hashes
- Consider changing
CMAKE_OSX_DEPLOYMENT_TARGET
- Execute and fix issue by issue...