[android][docs] Update to latest info (#83611)

This commit is contained in:
finagolfin
2025-08-09 01:44:53 +05:30
committed by GitHub
parent 5e246174a9
commit 1dbdf0c26f

View File

@@ -22,21 +22,17 @@ on an Android device, it takes a lot more than just the Swift stdlib to write
an app. You'd need some sort of framework to build a user interface for your
application, which the Swift stdlib does not provide.
Alternatively, one could theoretically call into Java interfaces from Swift,
but unlike as with Objective-C, the Swift compiler does nothing to facilitate
Swift-to-Java bridging.
## Prerequisites
To follow along with this guide, you'll need:
1. A Linux environment capable of building Swift from source, preferably
Ubuntu 22.04 or Ubuntu 20.04. Before attempting to build for Android,
Ubuntu 24.04 or Ubuntu 22.04. Before attempting to build for Android,
please make sure you are able to build for Linux by following the
instructions in the Swift project README.
2. The latest build of the Swift compiler for your Linux distro, available at
https://www.swift.org/download/ or sometimes your distro package manager.
3. The latest version of the Android LTS NDK (r27c at the time of this writing),
https://www.swift.org/install/linux/ or sometimes your distro package manager.
3. The latest version of the Android LTS NDK (r27d at the time of this writing),
available to download here:
https://developer.android.com/ndk/downloads
4. An Android device with remote debugging enabled or the emulator. We require
@@ -54,9 +50,9 @@ and the prebuilt Swift toolchain (add --skip-early-swift-driver if you already
have a Swift toolchain in your path):
```
$ NDK_PATH=path/to/android-ndk-r27c
$ SWIFT_PATH=path/to/swift-DEVELOPMENT-SNAPSHOT-2024-11-09-a-ubuntu22.04/usr/bin
$ git checkout swift-DEVELOPMENT-SNAPSHOT-2024-11-09-a
$ NDK_PATH=path/to/android-ndk-r27d
$ SWIFT_PATH=path/to/swift-DEVELOPMENT-SNAPSHOT-2025-08-07-a-ubuntu24.04/usr/bin
$ git checkout swift-DEVELOPMENT-SNAPSHOT-2025-08-07-a
$ utils/build-script \
-R \ # Build in ReleaseAssert mode.
--android \ # Build for Android.
@@ -83,11 +79,12 @@ Then use the standalone Swift stdlib from the previous step to compile a Swift
source file, targeting Android:
```
$ NDK_PATH="path/to/android-ndk-r27c"
$ SWIFT_PATH=path/to/swift-DEVELOPMENT-SNAPSHOT-2024-11-09-a-ubuntu22.04/usr/bin
$ NDK_PATH="path/to/android-ndk-r27d"
$ SWIFT_PATH=path/to/swift-DEVELOPMENT-SNAPSHOT-2025-08-07-a-ubuntu24.04/usr/bin
$ $SWIFT_PATH/swiftc \ # The prebuilt Swift compiler you downloaded
# The location of the tools used to build Android binaries
-tools-directory ${NDK_PATH}/toolchains/llvm/prebuilt/linux-x86_64/bin/ \
-disallow-use-new-driver \ # Work around a bug in the driver, a fix is in the works
-target aarch64-unknown-linux-android21 \ # Targeting Android aarch64 at API 21
-sdk ${NDK_PATH}/toolchains/llvm/prebuilt/linux-x86_64/sysroot \ # The SDK is the Android unified sysroot and the resource-dir is where you just built the Swift stdlib.
-resource-dir build/Ninja-ReleaseAssert/swift-linux-x86_64/lib/swift
@@ -135,7 +132,7 @@ $ adb push build/Ninja-ReleaseAssert/swift-linux-x86_64/lib/swift/android/libBlo
In addition, you'll also need to copy the Android NDK's libc++:
```
$ adb push /path/to/android-ndk-r27c/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so /data/local/tmp
$ adb push /path/to/android-ndk-r27d/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so /data/local/tmp
```
Finally, you'll need to copy the `hello` executable you built in the
@@ -178,7 +175,7 @@ $ utils/build-script \
-R \ # Build in ReleaseAssert mode.
-T \ # Run all tests, including on the Android device (add --host-test to only run Android tests on the Linux host).
--android \ # Build for Android.
--android-ndk ~/android-ndk-r27c \ # Path to an Android NDK.
--android-ndk ~/android-ndk-r27d \ # Path to an Android NDK.
--android-arch aarch64 \ # Optionally specify Android architecture, alternately armv7 or x86_64
--android-api-level 21
```