Skip to content

Commit eb8ea87

Browse files
committed
Try setting up an emulator in CI
1 parent bcbe288 commit eb8ea87

File tree

2 files changed

+104
-1
lines changed

2 files changed

+104
-1
lines changed

.github/workflows/ci.yml

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,64 @@ jobs:
4646
asset_name: android-frida-interception-script-${{ github.ref }}.js
4747
file: ./build/android-frida-interception-script.js
4848
tag: ${{ github.ref }}
49-
repo_token: ${{ secrets.GITHUB_TOKEN }}
49+
repo_token: ${{ secrets.GITHUB_TOKEN }}
50+
51+
test-android:
52+
name: Test on Android emulator
53+
runs-on: ubuntu-latest
54+
strategy:
55+
matrix:
56+
api-level: [30]
57+
steps:
58+
- uses: actions/checkout@v4
59+
60+
- name: Set up Python
61+
uses: actions/setup-python@v5
62+
with:
63+
python-version: '3.11'
64+
65+
- name: Install Frida CLI
66+
run: |
67+
pip install --user frida-tools
68+
echo "$HOME/.local/bin" >> $GITHUB_PATH
69+
70+
# Apparently significantly improves emulator performance:
71+
- name: Enable KVM
72+
run: |
73+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
74+
sudo udevadm control --reload-rules
75+
sudo udevadm trigger --name-match=kvm
76+
77+
# Cache the emulator AVD:
78+
- name: AVD cache
79+
uses: actions/cache@v4
80+
id: avd-cache
81+
with:
82+
path: |
83+
~/.android/avd/*
84+
~/.android/adb*
85+
key: avd-${{ matrix.api-level }}
86+
87+
- name: Create AVD and cache snapshot
88+
if: steps.avd-cache.outputs.cache-hit != 'true'
89+
uses: reactivecircus/android-emulator-runner@v2
90+
with:
91+
api-level: ${{ matrix.api-level }}
92+
target: google_apis
93+
force-avd-creation: false
94+
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
95+
script: |
96+
echo "Generated AVD snapshot for caching."
97+
98+
- name: Run tests
99+
uses: reactivecircus/android-emulator-runner@v2
100+
with:
101+
api-level: ${{ matrix.api-level }}
102+
target: google_apis
103+
force-avd-creation: false
104+
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
105+
script: |
106+
adb devices
107+
bash test/setup-emulator.sh
108+
echo "Emulator ready to test"
109+
adb shell pgrep -f frida-server

test/setup-emulator.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Assumes: Android emulator/device is available via ADB and Frida CLI is installed on computer
5+
# Wait for device, install APK, and set up Frida server (all idempotent)
6+
7+
# Wait for emulator/device to be available
8+
adb wait-for-device
9+
adb shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;'
10+
echo "Emulator/device booted."
11+
12+
# Download and install APK if not already installed
13+
APK_PATH="/tmp/pinning-demo.apk"
14+
APK_URL="https://github.com/httptoolkit/android-ssl-pinning-demo/releases/download/v1.4.1/pinning-demo.apk"
15+
PACKAGE="tech.httptoolkit.pinning_demo"
16+
if ! adb shell pm list packages | grep -q "$PACKAGE"; then
17+
wget -q $APK_URL -O $APK_PATH
18+
adb install -r $APK_PATH
19+
echo "APK installed."
20+
else
21+
echo "APK already installed."
22+
fi
23+
24+
# Set up Frida server
25+
FRIDA_VERSION=$(frida --version)
26+
FRIDA_SERVER_URL="https://github.com/frida/frida/releases/download/${FRIDA_VERSION}/frida-server-${FRIDA_VERSION}-android-x86_64.xz"
27+
FRIDA_SERVER_LOCAL="/tmp/frida-server"
28+
FRIDA_SERVER_REMOTE="/data/local/tmp/frida-server"
29+
30+
if ! adb shell pgrep -f frida-server > /dev/null; then
31+
if [ ! -f $FRIDA_SERVER_LOCAL ]; then
32+
wget -q $FRIDA_SERVER_URL -O /tmp/frida-server.xz
33+
unxz -f /tmp/frida-server.xz
34+
chmod +x $FRIDA_SERVER_LOCAL
35+
fi
36+
adb root || true
37+
adb push $FRIDA_SERVER_LOCAL $FRIDA_SERVER_REMOTE
38+
adb shell "chmod 755 $FRIDA_SERVER_REMOTE"
39+
adb shell "$FRIDA_SERVER_REMOTE" &
40+
echo "Frida server started on device."
41+
else
42+
echo "Frida server already running."
43+
fi

0 commit comments

Comments
 (0)