1- name : Android Gradle Build test logic
1+ name : Android Gradle Build and Test
22
33on :
4- workflow_call :
5- inputs :
6- os :
7- required : true
8- type : string
9- jdk_distro :
10- required : true
11- type : string
12- jdk_version :
13- required : true
14- type : string
4+ push :
5+ branches : [ 'master', 'main', 'release/**' ]
6+ pull_request :
7+ branches : [ 'master' ]
8+
9+ concurrency :
10+ group : android-${{ github.head_ref || github.ref }}
11+ cancel-in-progress : true
1512
1613jobs :
17- build_wolfssljni :
18- runs-on : ${{ inputs.os }}
14+ build_wolfcryptjni :
15+ runs-on : ubuntu-latest
1916 steps :
2017 - name : Clone wolfcrypt-jni
2118 uses : actions/checkout@v4
@@ -31,22 +28,80 @@ jobs:
3128 - name : Create blank options.h
3229 run : cp IDE/Android/app/src/main/cpp/wolfssl/wolfssl/options.h.in IDE/Android/app/src/main/cpp/wolfssl/wolfssl/options.h
3330
34- # Setup Java
31+ # Setup Java with Gradle caching
3532 - name : Setup java
3633 uses : actions/setup-java@v4
3734 with :
38- distribution : ${{ inputs.jdk_distro }}
39- java-version : ${{ inputs.jdk_version }}
35+ distribution : ' zulu'
36+ java-version : ' 21'
37+ cache : ' gradle'
38+
39+ # Build all targets in single Gradle invocation
40+ - name : Gradle Build
41+ run : cd IDE/Android && ./gradlew --build-cache assembleDebug assembleDebugUnitTest assembleDebugAndroidTest
4042
41- # Gradle assembleDebug
42- - name : Gradle assembleDebug
43- run : cd IDE/Android && ls && ./gradlew assembleDebug
43+ # Enable KVM for hardware acceleration (required for emulator)
44+ - name : Enable KVM
45+ run : |
46+ echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
47+ sudo udevadm control --reload-rules
48+ sudo udevadm trigger --name-match=kvm
4449
45- # Gradle assembleDebugUnitTest
46- - name : Gradle assembleDebugUnitTest
47- run : cd IDE/Android && ls && ./gradlew assembleDebugUnitTest
50+ # Cache AVD snapshot for faster emulator boot
51+ - name : AVD cache
52+ uses : actions/cache@v4
53+ id : avd-cache
54+ with :
55+ path : |
56+ ~/.android/avd/*
57+ ~/.android/adb*
58+ key : avd-wolfcryptjni-30-x86_64-atd-v1
4859
49- # Gradle assembleDebugAndroidTest
50- - name : Gradle assembleDebugAndroidTest
51- run : cd IDE/Android && ls && ./gradlew assembleDebugAndroidTest
60+ # Create AVD and generate snapshot for caching
61+ - name : Create AVD and generate snapshot
62+ if : steps.avd-cache.outputs.cache-hit != 'true'
63+ uses : reactivecircus/android-emulator-runner@v2
64+ with :
65+ api-level : 30
66+ arch : x86_64
67+ target : aosp_atd
68+ force-avd-creation : false
69+ emulator-options : -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
70+ disable-animations : true
71+ script : echo "Generated AVD snapshot for caching"
5272
73+ # Run instrumented tests on Android emulator
74+ - name : Run Android Instrumented Tests
75+ uses : reactivecircus/android-emulator-runner@v2
76+ timeout-minutes : 15
77+ with :
78+ api-level : 30
79+ arch : x86_64
80+ target : aosp_atd
81+ force-avd-creation : false
82+ emulator-options : -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
83+ disable-animations : true
84+ script : |
85+ adb wait-for-device
86+ adb shell mkdir -p /data/local/tmp/examples/certs/intermediate
87+ adb shell mkdir -p /data/local/tmp/examples/certs/rsapss
88+ adb shell mkdir -p /data/local/tmp/examples/certs/crl
89+ adb push ./examples/certs/ /data/local/tmp/examples/
90+ adb logcat -c
91+ cd IDE/Android && ./gradlew connectedDebugAndroidTest --no-daemon --no-watch-fs || { adb logcat -d > /tmp/logcat.txt 2>&1; echo "=== LOGCAT (errors) ==="; grep -i "exception\|error\|fatal" /tmp/logcat.txt || true; exit 1; }
92+ adb logcat -d > /tmp/logcat.txt 2>&1 || true
93+ pgrep -f '[q]emu-system' | xargs -r kill -9 2>/dev/null || true
94+ pgrep -f '[c]rashpad' | xargs -r kill -9 2>/dev/null || true
95+ sleep 2
96+
97+ # Upload test reports even on failure
98+ - name : Upload Test Reports
99+ uses : actions/upload-artifact@v4
100+ if : always()
101+ timeout-minutes : 5
102+ with :
103+ name : android-test-reports
104+ path : |
105+ IDE/Android/app/build/reports/androidTests/
106+ /tmp/logcat.txt
107+ retention-days : 14
0 commit comments