Automated scripts to build Swift Android cross compilation toolchain for macOS
Prebuilt toolchains are located on Github Releases
-
Download and install Swift toolchain 6.0.3
-
Install the Android NDK:
- If you have Android SDK Command-Line Tools installed:
sdkmanager --install "ndk;26.2.11394342"
- otherwise:
curl -O https://dl.google.com/android/repository/android-ndk-r26c-darwin.dmg
hdiutil attach android-ndk-r26c-darwin.dmg
cp -r "/Volumes/Android NDK r26c/AndroidNDK11394342.app/Contents/NDK/" ./android-ndk-r26c
hdiutil detach "/Volumes/Android NDK r26c"
- Install the Swift Android Toolchain
curl -L -O https://github.com/readdle/swift-android-toolchain/releases/latest/download/swift-android.zip
unzip swift-android.zip
- Set Up Environment Variables
export ANDROID_NDK_HOME=<PATH_TO_NDK>
export SWIFT_ANDROID_HOME=<PATH_TO_SWIFT_ANDROID>
export PATH=$ANDROID_NDK_HOME:$PATH
export PATH=$SWIFT_ANDROID_HOME/build-tools:$PATH
Our current swift build system is tiny wrapper over Swift PM. See Swift Package Manager docs for more info.
Command | Description |
---|---|
swift package clean | Clean build folder |
swift package update | Update dependencies |
swift android build | Build all products |
swift android build --build-tests | Build all products and tests |
swift android test | Connect to Android device and run all tests |
swift android build
wrapper scripts works as swift build
from Swift Package Manager but is configured for Android. You can pass additional parameters such as -Xswiftc -DDEBUG
, -Xswiftc -suppress-warnings
or --configuration release
Example of compilation flags:
- Debug
swift android build --configuration debug -Xswiftc -DDEBUG
- Release
swift android build --configuration release
swift android test
wrapper script builds, copies, and runs Swift Package Manager (SPM) tests on a connected Android device.
This plugin integrates Swift Android Toolchain to Gradle