1+ name : Android Build
2+
3+ # ## To build from subfolder,just modify the 'ANDROID_DIR'
4+
5+ on :
6+ push :
7+ # branches: [ "main","master","dev","release" ]
8+ # ## Start build only on these branches
9+ workflow_dispatch :
10+ # ## Support manual build in 'Actions/workflow'
11+
12+ env :
13+ ANDROID_DIR : .
14+ # ## Build from project root (when 'app' folder is just at project root)
15+ # ANDROID_DIR: android
16+ # ## Build from 'android' folder (when 'app' folder is in 'project/android' folder), modify it as you need.
17+ NDK_VERSION : 29.0.13599879
18+
19+ permissions :
20+ contents : write
21+
22+ jobs :
23+ build_apk :
24+ strategy :
25+ matrix :
26+ build_type : ['debug', 'release']
27+ # build_type: ['debug']
28+ name : Build APK
29+ runs-on : ubuntu-latest
30+ steps :
31+
32+ - name : Cancel previous runs
33+ uses : styfle/cancel-workflow-action@0.12.1
34+ with :
35+ access_token : ${{ github.token }}
36+
37+ - name : Checkout code
38+ uses : actions/checkout@v4
39+
40+ - name : Cache NDK
41+ uses : actions/cache@v3
42+ id : cache-ndk
43+ with :
44+ path : /usr/local/lib/android/sdk/ndk/${{ env.NDK_VERSION }}
45+ key : ${{ runner.os }}-ndk-${{ env.NDK_VERSION }}
46+
47+ - name : Accept Android licenses and install NDK
48+ if : steps.cache-ndk.outputs.cache-hit != 'true'
49+ run : |
50+ sudo apt-get update && sudo apt-get install -y expect
51+ expect -c '
52+ set timeout 300
53+ spawn /usr/local/lib/android/sdk/cmdline-tools/latest/bin/sdkmanager --licenses
54+ ### step1: handle Review licenses that have not been accepted (y/N)?"
55+ expect {
56+ "Review licenses that have not been accepted (y/N)?" {
57+ send "y\r"
58+ exp_continue
59+ }
60+ }
61+ ### step2: handle all licences
62+ while {[expect {
63+ "Accept? (y/N):" {
64+ send "y\r"
65+ exp_continue
66+ }
67+ ### ignore info of progress bar
68+ -re "\[.*\] \d+%.*" {
69+ exp_continue
70+ }
71+ ### when finished
72+ eof {
73+ return 1
74+ }
75+ }]} {}
76+ '
77+ ### install NDK
78+ /usr/local/lib/android/sdk/cmdline-tools/latest/bin/sdkmanager "ndk;${{ env.NDK_VERSION }}"
79+ shell : bash
80+
81+
82+ - name : Set up JDK 17
83+ uses : actions/setup-java@v4
84+ with :
85+ java-version : ' 17'
86+ distribution : ' temurin'
87+
88+ - name : Cache Gradle and build outputs
89+ uses : actions/cache@v3
90+ with :
91+ path : |
92+ ~/.gradle/caches
93+ ~/.gradle/wrapper
94+ ${{ env.ANDROID_DIR }}/app/build
95+ ${{ env.ANDROID_DIR }}/app/.cxx ### NDK cache dir
96+ key : ${{ runner.os }}-gradle-${{ hashFiles('**/gradle-wrapper.properties', '**/build.gradle', '**/CMakeLists.txt') }}
97+ restore-keys : |
98+ ${{ runner.os }}-gradle-
99+
100+ - name : Increase Gradle memory
101+ working-directory : ${{ env.ANDROID_DIR }}
102+ run : |
103+ printf "\norg.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=1g\n" >> gradle.properties
104+
105+ - name : Make gradlew executable
106+ working-directory : ${{ env.ANDROID_DIR }}
107+ run : |
108+ if [ ! -f "gradlew" ]; then gradle wrapper; fi
109+ chmod +x gradlew
110+
111+ - name : Build ${{ matrix.build_type }} APK
112+ working-directory : ${{ env.ANDROID_DIR }}
113+ run : |
114+ build_type=${{ matrix.build_type }}
115+ ./gradlew assemble${build_type^}
116+
117+ - name : Show apk paths
118+ run : |
119+ echo ">>${{ env.ANDROID_DIR }}/app/build/outputs/apk/${{ matrix.build_type }}:"
120+ ls -la ${{ env.ANDROID_DIR }}/app/build/outputs/apk/${{ matrix.build_type }}
121+
122+ - name : Copy ${{ matrix.build_type }} APK
123+ run : |
124+ cp ${{ env.ANDROID_DIR }}/app/build/outputs/apk/${{ matrix.build_type }}/*.apk ./
125+
126+ - name : Upload ${{ matrix.build_type }} APK
127+ uses : actions/upload-artifact@v4
128+ with :
129+ name : apk-${{ matrix.build_type }}
130+ path : app-${{ matrix.build_type }}.apk
0 commit comments