@@ -10,36 +10,39 @@ emulator](https://github.com/finagolfin/swift-android-sdk/blob/main/.github/work
10
10
The CI now builds with both the latest LTS NDK 26 and the last LTS NDK 25c. Now
11
11
that Swift 5.9 supports [ the new experimental SDK bundle
12
12
format] ( 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).
16
19
17
20
## Cross-compiling and testing Swift packages with the Android SDK
18
21
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
21
24
compiler] ( https://swift.org/download/#releases ) (make sure to install the Swift
22
25
compiler's dependencies listed there). Unpack these archives and the SDK.
23
26
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 `
25
28
to point to the clang headers that come with your swift compiler, eg
26
29
27
30
```
28
31
ln -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
30
33
```
31
34
32
35
Next, modify the cross-compilation JSON file ` android-aarch64.json ` in this repo
33
36
similarly:
34
37
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 ` .
37
40
38
41
2 . The path to the compiler should change from ` /home/finagolfin/swift-5.9.2-RELEASE-ubuntu22.04 `
39
42
to the path to your Swift compiler, ` /home/yourname/swift-5.9.2-RELEASE-ubi9 ` .
40
43
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 ` .
43
46
44
47
Now you're ready to cross-compile a Swift package with the cross-compilation
45
48
configuration JSON file, ` android-aarch64.json ` , and run its tests on Android.
@@ -51,7 +54,7 @@ cd swift-argument-parser/
51
54
52
55
/home/yourname/swift-5.9.2-RELEASE-ubuntu22.04/usr/bin/swift build --build-tests
53
56
--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
55
58
```
56
59
This will cross-compile the package for Android aarch64 and produce a test
57
60
runner 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
84
87
cd # move to the Termux app's home directory
85
88
pkg install openssh
86
89
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,
88
91
swift-argument-parserPackageTests.xctest,generate-manual,math,repeat,roll} .
89
92
90
- tar xf swift-5.9-android-24-sdk.tar.xz
93
+ tar xf swift-5.9.2 -android-24-sdk.tar.xz
91
94
92
95
./swift-argument-parserPackageTests.xctest
93
96
```
@@ -143,30 +146,29 @@ dependencies and include them yourself.
143
146
144
147
## Building the Android SDKs from source
145
148
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
147
150
repo and run
148
151
` SWIFT_TAG=swift-5.9.2-RELEASE ANDROID_ARCH=aarch64 swift get-packages-and-swift-source.swift `
149
152
to 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 `
151
154
for the latest Swift trunk snapshot and pass in the path to the corresponding
152
155
prebuilt Swift toolchain to ` build-script ` below, you can build a Swift trunk
153
156
SDK too, as seen on the CI.
154
157
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 :
159
162
```
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
162
164
```
163
165
164
166
After 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 )
165
167
are installed, run the following ` build-script ` command with your local paths
166
168
substituted instead:
167
169
```
168
170
./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
170
172
--build-swift-tools=0 --native-swift-tools-path=/home/finagolfin/swift-5.9.2-RELEASE-ubuntu22.04/usr/bin/
171
173
--native-clang-tools-path=/home/finagolfin/swift-5.9.2-RELEASE-ubuntu22.04/usr/bin/
172
174
--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
186
188
` libdispatch.so ` and Swift corelibs to include ` $ORIGIN ` and other relative
187
189
directories in their rpaths:
188
190
```
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
190
192
patchelf --set-rpath \$ORIGIN/../..:\$ORIGIN swift-release-android-aarch64-24-sdk/usr/lib/swift/android/lib*.so
191
193
```
192
194
@@ -199,7 +201,7 @@ API 24. Specifically, it downloads the libicu, libicu-static, libandroid-spawn,
199
201
libcurl, and libxml2 packages from the [ Termux package
200
202
repository] ( https://packages.termux.dev/apt/termux-main/pool/main/ ) .
201
203
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
203
205
the resulting files moved to a newly-created Swift release SDK directory:
204
206
```
205
207
mkdir swift-release-android-aarch64-24-sdk
@@ -214,14 +216,14 @@ rm swift-release-android-aarch64-24-sdk/usr/bin/*-config
214
216
cd swift-release-android-aarch64-24-sdk/usr/lib
215
217
216
218
rm 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
218
220
219
221
# 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
223
225
patchelf --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
225
227
```
226
228
The libcurl and libxml2 packages are [ only needed for the FoundationNetworking
227
229
and FoundationXML libraries respectively] ( https://github.com/apple/swift-corelibs-foundation/blob/release/5.9/Docs/ReleaseNotes_Swift5.md ) ,
0 commit comments