@@ -10,36 +10,39 @@ emulator](https://github.com/finagolfin/swift-android-sdk/blob/main/.github/work
1010The CI now builds with both the latest LTS NDK 26 and the last LTS NDK 25c. Now
1111that Swift 5.9 supports [ the new experimental SDK bundle
1212format] ( https://github.com/apple/swift-evolution/blob/main/proposals/0387-cross-compilation-destinations.md ) ,
13- I plan to distribute an Android SDK bundle for NDK 26 sometime in January. In
14- the meantime, you can get architecture-specific SDKs supporting either NDK from
15- the ` Artifacts ` section of a recent passing CI run and try it out.
13+ I plan to distribute an Android SDK bundle for NDK 26 sometime this month.
14+
15+ If you cannot build against NDK 26 and the Swift 5.9.2 SDK because of the newly
16+ added nullability annotations, use the previous NDK 25c and Swift 5.9 SDK instead,
17+ until you can get your package updated (you can still use the Swift 5.9.2
18+ compiler with the older Swift 5.9 SDK).
1619
1720## Cross-compiling and testing Swift packages with the Android SDK
1821
19- To build with the Swift 5.9 SDK, first download [ the last Android LTS NDK
20- 25c ] ( https://github. com/android/ ndk/wiki/Unsupported-Downloads ) and [ Swift 5.9.2
22+ To build with the Swift 5.9.2 SDK, first download [ the latest Android LTS NDK
23+ 26b ] ( https://developer.android. com/ndk/downloads ) and [ Swift 5.9.2
2124compiler] ( https://swift.org/download/#releases ) (make sure to install the Swift
2225compiler's dependencies listed there). Unpack these archives and the SDK.
2326
24- Change the symbolic link at ` swift-5.9-android-24-sdk/usr/lib/swift/clang `
27+ Change the symbolic link at ` swift-5.9.2 -android-24-sdk/usr/lib/swift/clang `
2528to point to the clang headers that come with your swift compiler, eg
2629
2730```
2831ln -sf /home/yourname/swift-5.9.2-RELEASE-ubuntu22.04/usr/lib/clang/13.0.0
29- swift-5.9-android-24-sdk/usr/lib/swift/clang
32+ swift-5.9.2 -android-24-sdk/usr/lib/swift/clang
3033```
3134
3235Next, modify the cross-compilation JSON file ` android-aarch64.json ` in this repo
3336similarly:
3437
35- 1 . All paths to the NDK should change from ` /home/finagolfin/android-ndk-r25c `
36- to the path to your NDK, ` /home/yourname/android-ndk-r25c ` .
38+ 1 . All paths to the NDK should change from ` /home/finagolfin/android-ndk-r26b `
39+ to the path to your NDK, ` /home/yourname/android-ndk-r26b ` .
3740
38412 . The path to the compiler should change from ` /home/finagolfin/swift-5.9.2-RELEASE-ubuntu22.04 `
3942to the path to your Swift compiler, ` /home/yourname/swift-5.9.2-RELEASE-ubi9 ` .
4043
41- 3 . The paths to the Android SDK should change from ` /home/finagolfin/swift-5.9-android-24-sdk `
42- to the path where you unpacked the Android SDK, ` /home/yourname/swift-5.9-android-24-sdk ` .
44+ 3 . The paths to the Android SDK should change from ` /home/finagolfin/swift-5.9.2 -android-24-sdk `
45+ to the path where you unpacked the Android SDK, ` /home/yourname/swift-5.9.2 -android-24-sdk ` .
4346
4447Now you're ready to cross-compile a Swift package with the cross-compilation
4548configuration JSON file, ` android-aarch64.json ` , and run its tests on Android.
@@ -51,7 +54,7 @@ cd swift-argument-parser/
5154
5255/home/yourname/swift-5.9.2-RELEASE-ubuntu22.04/usr/bin/swift build --build-tests
5356--destination ~/swift-android-sdk/android-aarch64.json
54- -Xlinker -rpath -Xlinker \$ORIGIN/swift-5.9-android-24-sdk/usr/lib/aarch64-linux-android
57+ -Xlinker -rpath -Xlinker \$ORIGIN/swift-5.9.2 -android-24-sdk/usr/lib/aarch64-linux-android
5558```
5659This will cross-compile the package for Android aarch64 and produce a test
5760runner executable with the ` .xctest ` extension, in this case at
@@ -84,10 +87,10 @@ uname -m # check if you're running on the right architecture, should say `aarch6
8487cd # move to the Termux app's home directory
8588pkg install openssh
8689
87- scp [email protected] :{swift-5.9-android-24-sdk.tar.xz, 90+ scp [email protected] :{swift-5.9.2 -android-24-sdk.tar.xz, 8891swift-argument-parserPackageTests.xctest,generate-manual,math,repeat,roll} .
8992
90- tar xf swift-5.9-android-24-sdk.tar.xz
93+ tar xf swift-5.9.2 -android-24-sdk.tar.xz
9194
9295./swift-argument-parserPackageTests.xctest
9396```
@@ -143,30 +146,29 @@ dependencies and include them yourself.
143146
144147## Building the Android SDKs from source
145148
146- Download the Swift 5.9.2 compiler and Android NDK 25c as above. Check out this
149+ Download the Swift 5.9.2 compiler and Android NDK 26b as above. Check out this
147150repo and run
148151` SWIFT_TAG=swift-5.9.2-RELEASE ANDROID_ARCH=aarch64 swift get-packages-and-swift-source.swift `
149152to get some prebuilt Android libraries and the Swift source to build the SDK. If
150- you pass in a different tag like ` swift-DEVELOPMENT-SNAPSHOT-2023-12-15 -a `
153+ you pass in a different tag like ` swift-DEVELOPMENT-SNAPSHOT-2024-01-08 -a `
151154for the latest Swift trunk snapshot and pass in the path to the corresponding
152155prebuilt Swift toolchain to ` build-script ` below, you can build a Swift trunk
153156SDK too, as seen on the CI.
154157
155- Next, add a header to the libdispatch source to work around a recent tightening
156- in how C headers are imported, apple/swift # 64321 , and apply a patch to the Swift
157- source, ` swift-android.patch ` from this repo, which adds a dependency for the
158- Foundation core library in this Android SDK :
158+ Next, apply a patch to the Swift source, ` swift-android.patch ` from this repo,
159+ which adds a dependency for the Foundation core library in this Android SDK, and
160+ two more patches that make modifications for the nullability annotations newly
161+ added in NDK 26 :
159162```
160- sed -i "s%#include <unistd%#include <signal.h>\n#include <unistd%" swift-corelibs-libdispatch/dispatch/dispatch.h
161- git apply swift-android.patch
163+ git apply swift-android.patch swift-android-both-ndks.patch swift-android-ndk26.patch
162164```
163165
164166After making sure [ needed build tools like python 3, CMake, and ninja] ( https://github.com/apple/swift/blob/release/5.9/docs/HowToGuides/GettingStarted.md#linux )
165167are installed, run the following ` build-script ` command with your local paths
166168substituted instead:
167169```
168170./swift/utils/build-script -RA --skip-build-cmark --build-llvm=0 --android
169- --android-ndk /home/finagolfin/android-ndk-r25c / --android-arch aarch64 --android-api-level 24
171+ --android-ndk /home/finagolfin/android-ndk-r26b / --android-arch aarch64 --android-api-level 24
170172--build-swift-tools=0 --native-swift-tools-path=/home/finagolfin/swift-5.9.2-RELEASE-ubuntu22.04/usr/bin/
171173--native-clang-tools-path=/home/finagolfin/swift-5.9.2-RELEASE-ubuntu22.04/usr/bin/
172174--host-cc=/usr/bin/clang-13 --host-cxx=/usr/bin/clang++-13
@@ -186,7 +188,7 @@ Finally, copy `libc++_shared.so` from the NDK and modify the cross-compiled
186188` libdispatch.so ` and Swift corelibs to include ` $ORIGIN ` and other relative
187189directories in their rpaths:
188190```
189- cp /home/yourname/android-ndk-r25c /toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so swift-release-android-aarch64-24-sdk/usr/lib
191+ cp /home/yourname/android-ndk-r26b /toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so swift-release-android-aarch64-24-sdk/usr/lib
190192patchelf --set-rpath \$ORIGIN/../..:\$ORIGIN swift-release-android-aarch64-24-sdk/usr/lib/swift/android/lib*.so
191193```
192194
@@ -199,7 +201,7 @@ API 24. Specifically, it downloads the libicu, libicu-static, libandroid-spawn,
199201libcurl, and libxml2 packages from the [ Termux package
200202repository] ( https://packages.termux.dev/apt/termux-main/pool/main/ ) .
201203
202- Each one is unpacked with ` ar x libicu_73.2_aarch64 .deb; tar xf data.tar.xz ` and
204+ Each one is unpacked with ` ar x libicu_74.1_aarch64 .deb; tar xf data.tar.xz ` and
203205the resulting files moved to a newly-created Swift release SDK directory:
204206```
205207mkdir swift-release-android-aarch64-24-sdk
@@ -214,14 +216,14 @@ rm swift-release-android-aarch64-24-sdk/usr/bin/*-config
214216cd swift-release-android-aarch64-24-sdk/usr/lib
215217
216218rm libicu{io,test,tu}*
217- patchelf --set-rpath \$ORIGIN libandroid-spawn.so libcurl.so libicu*so.73.2 libxml2.so
219+ patchelf --set-rpath \$ORIGIN libandroid-spawn.so libcurl.so libicu*so.74.1 libxml2.so
218220
219221# repeat the following for libicui18n.so and libicudata.so, as needed
220- rm libicuuc.so libicuuc.so.73
221- readelf -d libicuuc.so.73.2
222- mv libicuuc.so.73.2 libicuuc.so
222+ rm libicuuc.so libicuuc.so.74
223+ readelf -d libicuuc.so.74.1
224+ mv libicuuc.so.74.1 libicuuc.so
223225patchelf --set-soname libicuuc.so libicuuc.so
224- patchelf --replace-needed libicudata.so.73 libicudata.so libicuuc.so
226+ patchelf --replace-needed libicudata.so.74 libicudata.so libicuuc.so
225227```
226228The libcurl and libxml2 packages are [ only needed for the FoundationNetworking
227229and FoundationXML libraries respectively] ( https://github.com/apple/swift-corelibs-foundation/blob/release/5.9/Docs/ReleaseNotes_Swift5.md ) ,
0 commit comments