You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/articles/swift-android-getting-started.md
+26-26Lines changed: 26 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,21 +1,21 @@
1
1
---
2
2
layout: page
3
3
date: 2025-06-01 12:00:00
4
-
title: Getting Started with the Swift Android SDK
4
+
title: Getting Started with the Swift SDK for Android
5
5
author: [marcprux]
6
6
---
7
7
8
-
Since it was first open-sourced in 2015, Swift has grown from a language focused on creating apps for Darwinbased systems (iOS, macOS, etc.) into a cross-platform development language supporting Linux, Windows, and various embedded systems. With the release of the Swift Android SDK, it is now possible to use Swift for Android application development as well.
8
+
Since it was first open-sourced in 2015, Swift has grown from a language focused on creating apps for Darwin-based systems (iOS, macOS, etc.) into a cross-platform development language supporting Linux, Windows, and various embedded systems. With the release of the Swift SDK for Android, it is now possible to use Swift for Android application development as well.
9
9
10
10
### Getting Started
11
11
12
-
Building a Swift package for Android involves installing and configuring a cross-compilation SDK. Cross-compilation is the process of building code on one platform (the host) to run on a different platform (the target). In the context of Swift for Android, this typically involves compiling Swift code on a macOS or Linux machine (the host) to produce executables or libraries for Android devices (the target). This differs from compiling Swift for the host platform, where the host and target are the same (e.g., compiling and running Swift code on macOS for macOS).
12
+
Building a Swift package for Android involves installing and configuring a cross-compilation SDK. Cross-compilation is the process of building code on one platform, the host, to run on a different platform, the target. In the context of Swift for Android, this typically involves compiling Swift code on a host macOS or Linux machine to produce executables or libraries for the target Android OS. This differs from compiling Swift for the host platform, where the host and target are the same (e.g., compiling and running Swift code on macOS for macOS).
13
13
14
14
To cross-compile Swift code for Android, you need three separate components:
15
15
16
16
1.**The Host Toolchain**: this is the `swift` command and related tools that you will use to build and run your Swift code.
17
-
2.**The Swift Android SDK**: the set of libraries, headers, and other resources needed to generate and run Swift code for the Android target.
18
-
3.**The Android NDK**: the "native development kit" for Android includes the cross-compilation tools like `clang` that are used by the host toolchain to perform compilation and linking.
17
+
2.**The Swift SDK for Android**: the set of libraries, headers, and other resources needed to generate and run Swift code for the Android target.
18
+
3.**The Android NDK**: the "Native Development Kit" for Android includes the cross-compilation tools like `clang`and `ld`that are used by the host toolchain to cross-compile and perform linking.
19
19
20
20
21
21
#### 1. Install the Host Toolchain
@@ -25,56 +25,56 @@ The first thing to note is that while `swift` may already be installed on your s
25
25
The easiest and recommended way to manage host toolchains on macOS and Linux is to use the [swiftly](https://www.swift.org/swiftly/documentation/swiftly/getting-started) command. Once that has been setup, you can install the host toolchain with:
26
26
27
27
```console
28
-
$ swiftly install 6.1.1
29
-
Installing Swift 6.1.1
28
+
$ swiftly install 6.2
29
+
Installing Swift 6.2
30
30
Installing package in user home directory...
31
-
Swift 6.1.1 installed successfully!
31
+
Swift 6.2 installed successfully!
32
32
33
-
$ swiftly use 6.1.1
34
-
The global default toolchain has been set to `Swift 6.1.1` (was 6.1.0)
33
+
$ swiftly use 6.2
34
+
The global default toolchain has been set to `Swift 6.2` (was 6.1.0)
35
35
36
36
$ swiftly run swift --version
37
-
Apple Swift version 6.1.1 (swift-6.1.1-RELEASE)
37
+
Apple Swift version 6.2 (swift-6.2-RELEASE)
38
38
Target: arm64-apple-macosx15.0
39
39
```
40
40
41
-
#### 2. Install the Swift Android SDK
41
+
#### 2. Install the Swift SDK for Android
42
42
43
-
Next, you can download and install the SDK bundle using the built-in `swift sdk` command:
43
+
Next, download and install the SDK bundle using the built-in `swift sdk` command:
$ swiftly run swift sdk install swift-6.1.1-RELEASE-android-0.1.artifactbundle.tar.gz
48
-
Swift SDK bundle at `swift-6.1.1-RELEASE-android-0.1.artifactbundle.tar.gz` successfully installed as swift-6.1.1-RELEASE-android-0.1.artifactbundle.
46
+
$ swift sdk install https://github.com/swift-android-sdk/swift-android-sdk/releases/download/6.2/swift-6.2-RELEASE-android-0.1.artifactbundle.tar.gz --checksum ca7e09f09a591b6a661a39134aaf53b1b59d5e3a193b271ab1f20effdfc6e88e
47
+
48
+
Swift SDK bundle at `swift-6.2-RELEASE-android-0.1.artifactbundle.tar.gz` successfully installed as swift-6.2-RELEASE-android-0.1.artifactbundle.
49
49
```
50
50
51
51
You should now see the Android SDK included in the `swift sdk list` command:
52
52
53
53
```console
54
54
$ swiftly run swift sdk list
55
-
swift-6.1.1-RELEASE-android-0.1
55
+
swift-6.2-RELEASE-android-0.1
56
56
```
57
57
58
58
#### 3. Install and configure the Android NDK
59
59
60
-
The Swift Android SDK depends on the Android Native Development Toolkit (NDK) version 27c to provide the headers and tools necessary for cross-compiling to Android architectures. There are a variety of ways to [install the Android NDK](https://developer.android.com/ndk/guides), but the simplest is to just download and unzip the archive from the [NDK Downloads page](https://developer.android.com/ndk/downloads/#lts-downloads) directly.
60
+
The Swift SDK for Android depends on the Android Native Development Toolkit (NDK) version 27d to provide the headers and tools necessary for cross-compiling to Android architectures. There are a variety of ways to [install the Android NDK](https://developer.android.com/ndk/guides), but the simplest is to just download and unzip the archive from the [NDK Downloads page](https://developer.android.com/ndk/downloads/#lts-downloads) directly.
61
61
62
62
You can automate this with the following commands in a directory of your choosing:
Once you have downloaded and unpacked the NDK, you can link it up to the Swift Android SDK by running the `setup-android-sdk.sh` utility script included with the SDK bundle:
72
+
Once you have downloaded and unpacked the NDK, you can link it up to the Swift SDK for Android by running the `setup-android-sdk.sh` utility script included with the SDK bundle:
setup-android-sdk.sh: success: ndk-sysroot linked to Android NDK at android-ndk-r27d/toolchains/llvm/prebuilt
78
78
```
79
79
80
80
*Note that if you have already installed the NDK in a different location, you can simply set the `ANDROID_NDK_HOME` environment variable to that location and run the `setup-android-sdk.sh`*
@@ -108,7 +108,7 @@ $ .build/debug/hello
108
108
Hello, world!
109
109
```
110
110
111
-
With the Swift Android SDK installed and configured, you can now cross-compile the executable for Android for the `x86_64` architecture:
111
+
With the Swift SDK for Android installed and configured, you can now cross-compile the executable for Android for the `x86_64` architecture:
112
112
113
113
```console
114
114
$ swiftly run swift build --swift-sdk x86_64-unknown-linux-android28 --static-swift-stdlib
@@ -151,6 +151,6 @@ Congratulations, you have built and run your first Swift program on Android!
151
151
152
152
Note that Android applications are typically not deployed as command-line executable tools. Rather, they are assembled into an `.apk` archive and launched as an app from the home screen. To support this, Swift modules can be built as shared object libraries for each supported architecture and included in the app archive. The Swift code can then be accessed from the Android app — which is typically written in Java or Kotlin — through the Java Native Interface ([JNI](https://developer.android.com/training/articles/perf-jni)).
153
153
154
-
This is a larger development topic that will be expanded on in future articles and documentation. In the meantime, please visit the [Swift Android forums](https://forums.swift.org/c/development/android/) to discuss and seek help with the Swift Android SDK.
154
+
This is a larger development topic that will be expanded on in future articles and documentation. In the meantime, please visit the [Swift Android forums](https://forums.swift.org/c/platform/android/115) to discuss and seek help with the Swift SDK for Android.
0 commit comments