In June 2014 Apple introduced a brand new programming language obtainable to be used to develop for its platforms referred to as Swift. Swift was meant to be a contemporary substitute to Goal-C, which has been in use by builders because the 1980’s.
While Swift was initially a language owned by Apple, on December 3 2015 Apple made Swift an open supply venture. It additionally made Swift obtainable to be used on Linux working programs, committing it self to creating Swift within the open.
Since then by open supply efforts of Apple and the group Swift has discovered its means onto different platforms, together with Home windows and cloud companies like AWS. Soar to October twenty fourth 2025 and because of a devoted working group, Swift has discovered its means onto Android.
On this tutorial you’ll perceive how Swift works on Android, and undergo the steps to get Swift working in a primary Android venture.
What’s the Swift SDK for Android?
The Swift SDK for Android offers 3 principal elements required to run Swift on Android. They’re:
– The Host Toolchain (The compiler and instruments required to construct and run Swift code)
– The Swift SDK for Android (Libraries, headers and assets wanted to construct and run Swift code for Android)
– The Android NDK (The Native Improvement Equipment for Android, which permit code to be run on the Android platforms in different languages)
These elements work collectively to create machine code, which may run natively on Android units while additionally offering the efficiency and security of Swift.
Since most Android APIs are solely obtainable by way of Kotlin or Java, the Swift Android workgroup additionally offered a device referred to as swift-java. This generates bindings to allow swift to name by to Java code and vice versa utilizing the Java Native Interface (JNI).
Having executable Swift code callable by way of the JNI means you’ll be able to create reusable Swift Libraries throughout platforms, and name by to them by way of an Android app constructed usually. How thrilling!
Within the subsequent part you’ll use the Swift SDK for Android to create a small library operating in an Android app. Let’s get to it!
Organising the Swift SDK for Android
To point out the Swift SDK for Android in motion, you’ll use an instance venture offered by the Android working group to see how Swift code is named by the Android. You’ll then enhance it by writing one other perform in Swift that may be referred to as by the App.
First, set up Android Studio in case you don’t have it, then observe the directions right here on run an app on a system or an emulator.
Subsequent, clone the swift-android-examples repository to your laptop. Then, open the README.md on the prime of the venture.
The README explains what dependencies are wanted to construct the app. It’s fairly concerned so give it just a few reads earlier than continuing so you start.
While you’re prepared you’ll be able to start to proceed putting in the dependencies. The primary dependencies wanted are the Swift SDK for Android and Swiftly, a toolchain supervisor for Swift.
Comply with the directions obtainable right here to put in Swiftly. As soon as Swiftly is put in, set up a snapshot of the Swift SDK by persevering with to make use of the terminal:
swiftly set up main-snapshot-2025-12-17
As soon as the snapshot is put in, inform swiftly to start utilizing it.
swiftly use main-snapshot-2025-12-17
Lastly, check the snapshot is energetic by asking swift to run swift and let you know what model it’s.
swiftly run swift --version
It ought to reply with Apple Swift model 6.3-dev (LLVM 2bc32d2793f525d, Swift f1a704763ffd2c8) Goal: arm64-apple-macosx15.0 Construct config: +assertions.
As soon as the snapshot is operating appropriately, you’ll be able to set up the Swift SDK for Android. Utilizing the terminal enter the next command.
swift sdk set up https://obtain.swift.org/improvement/android-sdk/swift-DEVELOPMENT-SNAPSHOT-2025-12-17-a/swift-DEVELOPMENT-SNAPSHOT-2025-12-17-a_android.artifactbundle.tar.gz --checksum 5b5cd4da30ececb28c678c3a17a922f3c5fdb82f0ff6dc777bd44275fcc222e0
As soon as the Swift SDK for Android put in, you’ll be able to verify it obtainable in swiftly utilizing the sdk checklist command.
swiftly run swift sdk checklist
The terminal ought to output swift-DEVELOPMENT-SNAPSHOT-2025-12-17-a_android.
With the Swift SDK for Android put in. Now you can set up the Native Improvement Equipment for Android, you’ll do this within the subsequent part.
Organising the Native Improvement Equipment
To obtain the NDK and set it up for utilization, enter the next instructions into the terminal.
mkdir ~/android-ndk
cd ~/android-ndk
curl -fSLO https://dl.google.com/android/repository/android-ndk-r27d-$(uname -s).zip
unzip -q android-ndk-r27d-*.zip
export ANDROID_NDK_HOME=$PWD/android-ndk-r27d
Be happy to vary the placement of the `android-ndk` listing if wanted.
The instructions create a brand new listing to retailer the NDK, then navigates into the listing. It then downloads the NDK and unzips it into the listing. Lastly it provides the NDK into your terminal path for simple reference.
As soon as the NDK is put in and unzipped you’ll be able to then hyperlink it to the Swift SDK by operating a utility script offered. Enter the next command into the terminal to try this.
cd ~/Library/org.swift.swiftpm || cd ~/.swiftpm
./swift-sdks/swift-DEVELOPMENT-SNAPSHOT-2025-12-17-a_android.artifactbundle/swift-android/scripts/setup-android-sdk.sh
With that, you could have setup the Swift SDK for Android efficiently utilizing NDK. The following step to run the venture is to construct the Java packages wanted for the venture utilizing swift-java. Let’s do this subsequent.
Constructing Java Packages utilizing swift-java
To make use of swift-java you have to be certain the Java Improvement Equipment (JDK) is put in in your machine. You want JDK 25 as a result of some elements of swift-java are constructed utilizing it.
The advisable option to set up JDKs is to make use of a device referred to as sdkman, a bundle supervisor for software program improvement kits.
First, set up sdkman onto your machine utilizing the terminal.
curl -s "https://get.sdkman.io" | bash
Restart the terminal so sdkman may be added to your path. Then set up and set JDK 25 as your energetic JDK.
sdk set up java 25.0.1-amzn --use # solely with a purpose to publish swift-java artifacts regionally
export JAVA_HOME="${HOME}/.sdkman/candidates/java/present"
With the JDK setup, now you can start to generate the swift-java libraries wanted for the venture. Navigate to the swift-android-examples venture within the terminal and go into the `hashing-lib` listing.
cd hashing-lib
Run the resolve packages command from Swift to generate the packages.
swift bundle resolve
Lastly, publish the packages to your machines native maven repo. This can be a place the place artifacts and binaries can be utilized by different initiatives in your machine, just like maven central you will have used to retrieve dependencies remotely.
./.construct/checkouts/swift-java/gradlew --project-dir .construct/checkouts/swift-java :SwiftKitCore:publishToMavenLocal
As soon as the terminals report again the construct was profitable now you can run the app in Android Studio.
