@@ -18,7 +18,7 @@ error() { printf -- "** ERROR: %s\n" "$*" >&2; }
1818fatal () { error " $@ " ; exit 1; }
1919
2020ANDROID_PROFILE=" Nexus 10"
21- ANDROID_EMULATOR_LAUNCH_TIMEOUT =300
21+ ANDROID_EMULATOR_TIMEOUT =300
2222
2323SWIFTPM_HOME=" ${XDG_CONFIG_HOME} " /swiftpm
2424# e.g., "${SWIFTPM_HOME}"/swift-sdks/swift-DEVELOPMENT-SNAPSHOT-2025-12-11-a_android.artifactbundle/
@@ -36,6 +36,10 @@ while [[ $# -gt 0 ]]; do
3636 ANDROID_PROFILE=" ${1#* =} "
3737 shift
3838 ;;
39+ --android-emulator-timeout=* )
40+ ANDROID_EMULATOR_TIMEOUT=" ${1#* =} "
41+ shift
42+ ;;
3943 -* )
4044 fatal " Unknown option: $1 "
4145 ;;
5256
5357# extract the API level from the end of the triple
5458ANDROID_API=" ${ANDROID_SDK_TRIPLE/* -unknown-linux-android/ } "
59+
5560# extract the build arch from the beginning of the triple
5661ANDROID_EMULATOR_ARCH=" ${ANDROID_SDK_TRIPLE/ -unknown-linux-android*/ } "
5762
@@ -65,9 +70,9 @@ log "SWIFT_ANDROID_SDK_HOME=${SWIFT_ANDROID_SDK_HOME}"
6570# install and start an Android emulator
6671log " Listing installed Android SDKs"
6772export PATH=" ${PATH} :$ANDROID_HOME /emulator:$ANDROID_HOME /tools:$ANDROID_HOME /build-tools/latest:$ANDROID_HOME /platform-tools:$ANDROID_HOME /cmdline-tools/latest/bin"
73+ sdkmanager --list_installed
6874
6975log " Updating Android SDK licenses"
70- sdkmanager --list_installed
7176yes | sdkmanager --licenses > /dev/null || true
7277
7378log " Installing Android emulator"
@@ -89,7 +94,7 @@ log "Starting Android emulator"
8994nohup emulator -no-metrics -partition-size 1024 -memory 4096 -wipe-data -no-window -no-snapshot -noaudio -no-boot-anim -avd " ${ANDROID_EMULATOR_NAME} " &
9095
9196log " Waiting for Android emulator startup"
92- timeout ${ANDROID_EMULATOR_LAUNCH_TIMEOUT } adb wait-for-any-device
97+ timeout ${ANDROID_EMULATOR_TIMEOUT } adb wait-for-any-device
9398
9499log " Prepare Swift test package"
95100# create a staging folder where we copy the test executable
@@ -103,11 +108,11 @@ BUILD_DIR=.build/"${ANDROID_SDK_TRIPLE}"/debug
103108find " ${BUILD_DIR} " -name ' *.xctest' -exec cp -av {} " ${STAGING_DIR} " \;
104109find " ${BUILD_DIR} " -name ' *.resources' -exec cp -av {} " ${STAGING_DIR} " \;
105110
106- # also copy required libraries
111+ # copy over the required library dependencies
107112cp -av " ${SWIFT_ANDROID_SDK_HOME} " /swift-android/swift-resources/usr/lib/swift-" ${ANDROID_EMULATOR_ARCH_TRIPLE} " /android/* .so " ${SWIFT_ANDROID_SDK_HOME} " /swift-android/ndk-sysroot/usr/lib/" ${ANDROID_EMULATOR_ARCH_TRIPLE} " -linux-android/libc++_shared.so " ${STAGING_DIR} "
108113
109114# for the common case of tests referencing
110- # their own files as hardwired resource paths
115+ # their own files as hardwired paths instead of resources
111116if [[ -d Tests ]]; then
112117 cp -a Tests " ${STAGING_DIR} "
113118fi
@@ -119,11 +124,12 @@ adb push "${STAGING_DIR}" "${ANDROID_TMP_FOLDER}"
119124
120125TEST_CMD=" ./*.xctest"
121126TEST_SHELL=" cd ${ANDROID_TMP_FOLDER} "
122- TEST_SHELL=" ${TEST_SHELL} && ${TEST_CMD} "
127+ TEST_SHELL=" ${TEST_SHELL} && ${TEST_CMD} --testing-library xctest "
123128
124129# Run test cases a second time with the Swift Testing library
125- # We additionally need to handle the special exit code EXIT_NO_TESTS_FOUND (69 on Android),
126- # which can happen when the tests link to Testing, but no tests are executed
130+ # We additionally need to handle the special exit code
131+ # EXIT_NO_TESTS_FOUND (69 on Android), which can happen
132+ # when the tests link to Testing, but no tests are executed
127133# see: https://github.com/swiftlang/swift-package-manager/blob/main/Sources/Commands/SwiftTestCommand.swift#L1571
128134TEST_SHELL=" ${TEST_SHELL} && ${TEST_CMD} --testing-library swift-testing && [ \$ ? -eq 0 ] || [ \$ ? -eq 69 ]"
129135
0 commit comments