Skip to content

Commit 7c0309e

Browse files
committed
Use native adb on ARM runners and auto-detect instrumentation
1 parent 1e119ef commit 7c0309e

File tree

1 file changed

+11
-41
lines changed

1 file changed

+11
-41
lines changed

.github/workflows/scripts-android.yml

Lines changed: 11 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -55,34 +55,12 @@ jobs:
5555
accept-android-sdk-licenses: false
5656
packages: ''
5757

58-
- name: Ensure Android tools available on PATH
58+
- name: Install adb for ARM environment
5959
shell: bash
6060
run: |
6161
set -euxo pipefail
62-
if ! command -v sdkmanager >/dev/null 2>&1; then
63-
echo "sdkmanager executable is required" >&2
64-
exit 1
65-
fi
66-
67-
SDKMANAGER="$(command -v sdkmanager)"
68-
69-
run_sdk() {
70-
set +o pipefail
71-
yes | "$SDKMANAGER" "$@" >/dev/null 2>&1
72-
local rc=${PIPESTATUS[1]}
73-
set -o pipefail
74-
return $rc
75-
}
76-
77-
run_sdk --licenses
78-
run_sdk --install "platform-tools" "build-tools;34.0.0"
79-
run_sdk --install "platforms;android-33" || echo "Warning: failed to install Android 33 platform" >&2
80-
if [ -n "${ANDROID_HOME:-}" ] && [ -d "${ANDROID_HOME}/platform-tools" ]; then
81-
echo "${ANDROID_HOME}/platform-tools" >> "$GITHUB_PATH"
82-
fi
83-
if [ -n "${ANDROID_SDK_ROOT:-}" ] && [ -d "${ANDROID_SDK_ROOT}/platform-tools" ]; then
84-
echo "${ANDROID_SDK_ROOT}/platform-tools" >> "$GITHUB_PATH"
85-
fi
62+
sudo apt-get update -y
63+
sudo apt-get install -y adb
8664
command -v adb
8765
adb version
8866
@@ -106,31 +84,23 @@ jobs:
10684
adb install -r "artifacts/${{ needs.build-android.outputs.app_apk }}"
10785
adb install -r -t "artifacts/${{ needs.build-android.outputs.test_apk }}"
10886
adb logcat -c
109-
AAPT_BIN=""
110-
if command -v aapt >/dev/null 2>&1; then
111-
AAPT_BIN="$(command -v aapt)"
112-
elif [ -n "${ANDROID_HOME:-}" ] && [ -d "${ANDROID_HOME}/build-tools" ]; then
113-
AAPT_BIN="$(find "${ANDROID_HOME}/build-tools" -maxdepth 2 -name aapt -type f | sort | tail -n1 || true)"
114-
elif [ -n "${ANDROID_SDK_ROOT:-}" ] && [ -d "${ANDROID_SDK_ROOT}/build-tools" ]; then
115-
AAPT_BIN="$(find "${ANDROID_SDK_ROOT}/build-tools" -maxdepth 2 -name aapt -type f | sort | tail -n1 || true)"
116-
fi
117-
87+
PACKAGE_NAME="${{ needs.build-android.outputs.package_name }}"
11888
TEST_PACKAGE=""
11989
INSTRUMENTATION_NAME=""
120-
if [ -n "$AAPT_BIN" ] && [ -x "$AAPT_BIN" ]; then
121-
BADGING_OUTPUT="$($AAPT_BIN dump badging artifacts/${{ needs.build-android.outputs.test_apk }} || true)"
122-
if [ -n "$BADGING_OUTPUT" ]; then
123-
TEST_PACKAGE="$(printf '%s\n' "$BADGING_OUTPUT" | awk -F"'" '/^package: /{print $2; exit}')"
124-
INSTRUMENTATION_NAME="$(printf '%s\n' "$BADGING_OUTPUT" | awk -F"'" '/^instrumentation: /{print $2; exit}')"
125-
fi
90+
91+
INSTRUMENTATION_LINE="$(adb shell cmd package list instrumentation | tr -d '\r' | grep "target=${PACKAGE_NAME})" || true)"
92+
if [ -n "$INSTRUMENTATION_LINE" ]; then
93+
INSTRUMENTATION_NAME="${INSTRUMENTATION_LINE#instrumentation:}"
94+
INSTRUMENTATION_NAME="${INSTRUMENTATION_NAME%% (*}"
95+
TEST_PACKAGE="${INSTRUMENTATION_NAME%%/*}"
12696
fi
12797
12898
if [ -n "$INSTRUMENTATION_NAME" ]; then
12999
echo "Running instrumentation tests via $INSTRUMENTATION_NAME"
130100
adb shell am instrument -w "$INSTRUMENTATION_NAME"
131101
else
132102
if [ -z "$TEST_PACKAGE" ]; then
133-
TEST_PACKAGE="${{ needs.build-android.outputs.package_name }}.tests"
103+
TEST_PACKAGE="${PACKAGE_NAME}.tests"
134104
fi
135105
echo "Instrumentation runner not found, launching $TEST_PACKAGE via monkey"
136106
adb shell monkey -p "$TEST_PACKAGE" 1

0 commit comments

Comments
 (0)