-
Notifications
You must be signed in to change notification settings - Fork 47
236 lines (200 loc) · 7.45 KB
/
build-android.yml
File metadata and controls
236 lines (200 loc) · 7.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
name: Build Android
on:
workflow_dispatch:
push:
branches:
- main
paths:
- '.github/workflows/build-android.yml'
- 'package/cpp/**'
- 'package/android/**'
- 'examples/**/android/**'
- 'bun.lock'
pull_request:
paths:
- '.github/workflows/build-android.yml'
- 'package/cpp/**'
- 'package/android/**'
- 'examples/**/android/**'
- 'bun.lock'
jobs:
build-filament:
name: Build Filament for Android
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
# Problem: there is only 14 GB of disk space available on GitHub runners
# Solution: free up space by removing unneeded files
- name: Freeup space
run: |
df -h
echo "Removing hosted toolcache..."
sudo rm -rf /opt/hostedtoolcache || true
echo "Removing .NET..."
sudo rm -rf /usr/share/dotnet || true
echo "Removing GHC / Haskell..."
sudo rm -rf /opt/ghc || true
sudo rm -rf /usr/local/.ghcup || true
df -h
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Apply patches and calculate hash
id: hash
working-directory: package/
run: |
bun patch-filament
HASH=$(find ../filament -type f \( -name "*.cpp" -o -name "*.h" -o -name "*.cc" -o -name "CMakeLists.txt" \) -print0 | sort -z | xargs -0 sha256sum | sha256sum | cut -d' ' -f1 | head -c 16)
echo "hash=$HASH" >> $GITHUB_OUTPUT
echo "Filament hash: $HASH"
- name: Restore from cache
id: cache
uses: actions/cache/restore@v4
with:
path: package/android/libs/filament/
key: filament-android-debug-${{ steps.hash.outputs.hash }}
- name: Install build dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-get update
sudo apt-get install -y clang-16 libc++-16-dev libc++abi-16-dev ninja-build
sudo apt-get install -y mesa-common-dev libxi-dev libxxf86vm-dev libxrandr-dev libxinerama-dev libxcursor-dev libx11-xcb-dev
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/clang-16 100
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++-16 100
- name: Setup Android SDK
if: steps.cache.outputs.cache-hit != 'true'
uses: android-actions/setup-android@v3
- name: Install Android NDK and CMake
if: steps.cache.outputs.cache-hit != 'true'
run: |
sdkmanager --install "ndk;29.0.14206865" "cmake;3.22.1"
- name: Build Filament
if: steps.cache.outputs.cache-hit != 'true'
working-directory: package/
run: bash scripts/build-filament.sh debug --platform android
- name: Save to cache
if: steps.cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: package/android/libs/filament/
key: filament-android-debug-${{ steps.hash.outputs.hash }}
- name: Upload Filament libraries
uses: actions/upload-artifact@v4
with:
name: filament-android
path: package/android/libs/filament/
retention-days: 1
build-bullet3:
name: Build bullet3 for Android
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Calculate hash
id: hash
run: |
HASH=$(find bullet3/src -type f \( -name "*.cpp" -o -name "*.h" \) -print0 | sort -z | xargs -0 sha256sum | sha256sum | cut -d' ' -f1 | head -c 16)
echo "hash=$HASH" >> $GITHUB_OUTPUT
echo "bullet3 hash: $HASH"
- name: Restore from cache
id: cache
uses: actions/cache/restore@v4
with:
path: package/android/libs/bullet3/
key: bullet3-android-${{ steps.hash.outputs.hash }}
- name: Setup Android SDK
if: steps.cache.outputs.cache-hit != 'true'
uses: android-actions/setup-android@v3
- name: Install Android NDK
if: steps.cache.outputs.cache-hit != 'true'
run: |
sdkmanager --install "ndk;27.1.12297006"
- name: Build bullet3
if: steps.cache.outputs.cache-hit != 'true'
working-directory: package/
run: bash scripts/build-bullet3.sh --platform android
- name: Save to cache
if: steps.cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: package/android/libs/bullet3/
key: bullet3-android-${{ steps.hash.outputs.hash }}
- name: Upload bullet3 libraries
uses: actions/upload-artifact@v4
with:
name: bullet3-android
path: package/android/libs/bullet3/
retention-days: 1
build:
name: Build ${{ matrix.app }} (${{ matrix.variant }})
runs-on: ubuntu-latest
needs: [build-filament, build-bullet3]
strategy:
matrix:
app: [AppExampleFabric, ExpoExample]
variant: [debug, release]
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Setup JDK 17
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 17
java-package: jdk
- name: Restore bun cache
uses: actions/cache@v4
with:
path: ~/.bun/install/cache
key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lock') }}
restore-keys: |
${{ runner.os }}-bun-
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Download Filament libraries
uses: actions/download-artifact@v4
with:
name: filament-android
path: package/android/libs/filament/
- name: Download bullet3 libraries
uses: actions/download-artifact@v4
with:
name: bullet3-android
path: package/android/libs/bullet3/
- name: Restore Gradle cache
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Build Android app (AppExampleFabric)
if: matrix.app == 'AppExampleFabric'
working-directory: examples/AppExampleFabric/android
run: ./gradlew assemble${{ matrix.variant == 'debug' && 'Debug' || 'Release' }} --build-cache
- name: Prebuild Expo app
if: matrix.app == 'ExpoExample'
working-directory: examples/ExpoExample
run: bunx expo prebuild --platform android
- name: Build Android app (ExpoExample)
if: matrix.app == 'ExpoExample'
working-directory: examples/ExpoExample/android
run: ./gradlew assemble${{ matrix.variant == 'debug' && 'Debug' || 'Release' }} --build-cache
- name: Upload .apk to GitHub
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.app }}-${{ matrix.variant }}.apk
path: examples/${{ matrix.app }}/android/app/build/outputs/apk/${{ matrix.variant }}/app-${{ matrix.variant }}.apk
if-no-files-found: error