swift-android-toolchain

More: Author   ReportBugs   
Tags:

Automated scripts to build Swift Android cross compilation toolchain for macOS

Installation

Prebuilt toolchains are located on Github Releases

Prepare environment (macOS x86_64 or macOS arm64)

  1. Install Swift 6.1 toolchain with swiftly
swiftly install 6.1
  1. Install the Android NDK 27c
  2. If you have Android SDK Command-Line Tools installed:

    sdkmanager --install "ndk;27.2.12479018"
    
  3. 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
    
  4. Set Up Environment Variables ``` export ANDROID_NDK_HOME= export SWIFT_ANDROID_HOME=

export PATH=$ANDROID_NDK_HOME:$PATH export PATH=$SWIFT_ANDROID_HOME/build-tools:$PATH


### Build and Test swift modules

Our current swift build system is tiny wrapper over Swift PM. See [Swift Package Manager](https://github.com/apple/swift-package-manager/blob/master/Documentation/Usage.md) docs for more info.

| Command                             | Description                  |
|-------------------------------------|------------------------------|
| 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.

Build swift modules with Android Studio

This plugin integrates Swift Android Toolchain to Gradle

Other swift releated projects and articles

  1. Swift for Android: Our Experience and Tools
  2. Anotation Processor for generating JNI code
  3. Cross-platform swift weather app
Apps
About Me
GitHub: Trinea
Facebook: Dev Tools