@@ -80,12 +80,13 @@ log "Installing Android cmdline-tools"
8080mkdir ~ /android-sdk
8181pushd ~ /android-sdk
8282export ANDROID_HOME=${PWD}
83- # TODO: require that this be set by an argument
84- export ANDROID_NDK_HOME=" ${ANDROID_NDK_HOME:- ${ANDROID_HOME} } "
8583
8684curl --connect-timeout 30 --retry 3 --retry-delay 2 --retry-max-time 60 -fsSL -o commandlinetools.zip https://dl.google.com/android/repository/commandlinetools-linux-13114758_latest.zip
8785unzip commandlinetools.zip
8886rm commandlinetools.zip
87+ # a quirk of the archive is that its root is cmdline-tools,
88+ # but when executed they are expected to be at cmdline-tools/latest
89+ # or else the other relative paths are not identified correctly
8990mv cmdline-tools latest
9091mkdir cmdline-tools
9192mv latest cmdline-tools
@@ -99,18 +100,18 @@ popd
99100log " Listing installed Android SDKs"
100101sdkmanager --list_installed
101102
102- log " Updating Android licenses"
103+ log " Updating Android SDK licenses"
103104yes | sdkmanager --licenses > /dev/null || true
104105
105106log " Installing Android emulator"
106- sdkmanager --install " ${EMULATOR_SPEC} " " emulator" " platform-tools" " platforms;android-${ANDROID_API} "
107+ sdkmanager --install " emulator" " platform-tools" " platforms;android-${ANDROID_API} " " ${EMULATOR_SPEC }"
107108
108109log " Creating Android emulator"
109110avdmanager create avd -n " ${EMULATOR_NAME} " -k " ${EMULATOR_SPEC} " --device " ${ANDROID_PROFILE} "
110- # ANDROID_AVD_CONFIG="${ANDROID_AVD_HOME}"/"${EMULATOR_NAME}".avd/config.ini
111- # mkdir -p "$(dirname ${ANDROID_AVD_CONFIG})"
111+ ANDROID_AVD_CONFIG=" ${ANDROID_AVD_HOME} " /" ${EMULATOR_NAME} " .avd/config.ini
112+ mkdir -p " $( dirname ${ANDROID_AVD_CONFIG} ) "
112113# ~2G partition size
113- # echo 'disk.dataPartition.size=2000000000 ' >> "${ANDROID_AVD_CONFIG}"
114+ echo ' disk.dataPartition.size=1024MB ' >> " ${ANDROID_AVD_CONFIG} "
114115
115116log " Listing Android emulators"
116117emulator -list-avds
@@ -130,12 +131,9 @@ df -h
130131
131132log " Starting Android emulator"
132133
133- # launch the emulator in the background; we will cat the logs at the end
134- # TODO: -no-accel disables the need for KVM, but is very slow
135- nohup emulator -no-accel -no-metrics -partition-size 1024 -memory 4096 -avd " ${EMULATOR_NAME} " -wipe-data -no-window -no-snapshot -noaudio -no-boot-anim &
136- # 2>&1 > emulator.log &
137-
138- # adb logcat 2>&1 > logcat.log &
134+ # launch the emulator in the background
135+ # -no-accel disables the need for KVM, but is very slow
136+ nohup emulator -no-accel -no-metrics -partition-size 1024 -memory 4096 -wipe-data -no-window -no-snapshot -noaudio -no-boot-anim -avd " ${EMULATOR_NAME} " &
139137
140138log " Waiting for Android emulator startup"
141139timeout ${ANDROID_EMULATOR_LAUNCH_TIMEOUT} adb wait-for-any-device
@@ -154,7 +152,8 @@ if [[ -d Tests ]]; then
154152 cp -a Tests .build/" ${STAGING_DIR} "
155153fi
156154
157- cd .build/
155+ pushd .build/
156+
158157TEST_PACKAGE=$( find debug/ -name ' *.xctest' | tail -n 1 | xargs basename)
159158cp -a debug/" ${TEST_PACKAGE} " " ${STAGING_DIR} "
160159find debug/ -name ' *.resources' -exec cp -a {} " ${STAGING_DIR} " \;
@@ -166,7 +165,7 @@ log "Copy Swift test package to emulator"
166165ANDROID_TMP_FOLDER=" /data/local/tmp/${STAGING_DIR} "
167166adb push " ${STAGING_DIR} " " ${ANDROID_TMP_FOLDER} "
168167
169- cd -
168+ popd
170169
171170TEST_CMD=" ./${TEST_PACKAGE} "
172171TEST_SHELL=" cd ${ANDROID_TMP_FOLDER} "
@@ -175,11 +174,10 @@ TEST_SHELL="${TEST_SHELL} && ${TEST_CMD}"
175174# Run test cases a second time with the Swift Testing library
176175# We additionally need to handle the special exit code EXIT_NO_TESTS_FOUND (69 on Android),
177176# which can happen when the tests link to Testing, but no tests are executed
178- # see: https://github.com/swiftlang/swift-package-manager/blob/1b593469e8ad3daf2cc10e798340bd2de68c402d /Sources/Commands/SwiftTestCommand.swift#L1542
177+ # see: https://github.com/swiftlang/swift-package-manager/blob/main /Sources/Commands/SwiftTestCommand.swift#L1571
179178TEST_SHELL=" ${TEST_SHELL} && ${TEST_CMD} --testing-library swift-testing && [ \$ ? -eq 0 ] || [ \$ ? -eq 69 ]"
180179
181180log " Run Swift package tests"
182181
183182# run the test executable
184- adb shell " ls ${ANDROID_TMP_FOLDER} "
185183adb shell " ${TEST_SHELL} "
0 commit comments