|
1 | | -# Local Android Build Workflow - Setup Guide |
2 | | - |
3 | | -## Overview |
4 | | - |
5 | | -This guide helps you set up a self-hosted GitHub Actions runner on your local machine to build APKs directly using Gradle, bypassing Expo.dev's build service and associated costs. |
6 | | - |
7 | | -**File:** `.github/workflows/local-android-build.yml` |
8 | | - |
9 | | -## Why This Workflow? |
10 | | - |
11 | | -- ✅ **No Expo.dev costs** - Build directly on your machine |
12 | | -- ✅ **Full control** - Customize build process as needed |
13 | | -- ✅ **Faster feedback** - No cloud queue delays |
14 | | -- ⚠️ **Machine dependency** - Runner must be online and accessible |
15 | | - |
16 | | -## Prerequisites |
17 | | - |
18 | | -Before setting up the runner, ensure your machine has: |
19 | | - |
20 | | -### 1. Android SDK & Build Tools |
21 | | -- **Android SDK installed** (API level 34+) |
22 | | -- **Android Build Tools** (latest recommended) |
23 | | -- **ANDROID_HOME environment variable** set |
24 | | - |
25 | | -```bash |
26 | | -# Check current setup |
27 | | -echo $ANDROID_HOME |
28 | | - |
29 | | -# If not set, add to ~/.bashrc or ~/.zshrc: |
30 | | -# export ANDROID_HOME=~/Android/Sdk |
31 | | -# export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools |
32 | | -``` |
33 | | - |
34 | | -### 2. Java Development Kit (JDK) |
35 | | -- **Java 17+** (required for Android Gradle Plugin 8.x) |
36 | | - |
37 | | -```bash |
38 | | -java -version # Should be 17 or higher |
39 | | -``` |
40 | | - |
41 | | -### 3. Node.js |
42 | | -- **Node.js 22.x** (or version specified in your app) |
43 | | - |
44 | | -```bash |
45 | | -node -v |
46 | | -npm -v |
47 | | -``` |
48 | | - |
49 | | -### 4. Git |
50 | | -- Git must be configured globally |
51 | | - |
52 | | -```bash |
53 | | -git config --global user.name "Your Name" |
54 | | -git config --global user.email "your@email.com" |
55 | | -``` |
56 | | - |
57 | | -## Setting Up Self-Hosted Runner |
58 | | - |
59 | | -### Step 1: Create Personal Access Token (PAT) |
60 | | - |
61 | | -1. Go to **GitHub.com** → **Settings** → **Developer settings** → **Personal access tokens** → **Tokens (classic)** |
62 | | -2. Click **Generate new token (classic)** |
63 | | -3. Set **Expiration:** 90 days (or longer) |
64 | | -4. Select scopes: |
65 | | - - ✅ `repo` (Full control of private repositories) |
66 | | - - ✅ `admin:repo_hook` (Write access to hooks in public or private repositories) |
67 | | - - ✅ `admin:org_hook` (Read:org_hook) |
68 | | -5. Click **Generate token** and copy it immediately |
69 | | -6. Store it securely (you won't see it again) |
70 | | - |
71 | | -### Step 2: Configure Runner on Your Machine |
72 | | - |
73 | | -```bash |
74 | | -# Navigate to your project directory |
75 | | -cd /home/digitalnomad91/codebuilder-app |
76 | | - |
77 | | -# Create runner directory |
78 | | -mkdir -p ~/.github-runner |
79 | | -cd ~/.github-runner |
80 | | - |
81 | | -# Download the runner (Linux example - adjust for your OS) |
82 | | -curl -o actions-runner-linux-x64-2.315.0.tar.gz \ |
83 | | - -L https://github.com/actions/runner/releases/download/v2.315.0/actions-runner-linux-x64-2.315.0.tar.gz |
84 | | - |
85 | | -# Extract |
86 | | -tar xzf ./actions-runner-linux-x64-2.315.0.tar.gz |
87 | | - |
88 | | -# Configure the runner |
89 | | -./config.sh --url https://github.com/codebuilderinc/codebuilder-app \ |
90 | | - --token YOUR_GITHUB_TOKEN_HERE |
91 | | -``` |
92 | | - |
93 | | -During configuration: |
94 | | -- **Runner name:** Something like `local-build-machine` or `my-mac` |
95 | | -- **Work directory:** Press Enter to use default (`_work`) |
96 | | -- **Labels:** Optional (e.g., `self-hosted,linux`) |
97 | | -- **Default:** Accept defaults |
98 | | - |
99 | | -### Step 3: Run the Runner |
100 | | - |
101 | | -#### Option A: Run in Foreground (Testing) |
102 | | -```bash |
103 | | -cd ~/.github-runner |
104 | | -./run.sh |
105 | | -``` |
106 | | - |
107 | | -#### Option B: Run as Service (Recommended for 24/7) |
108 | | - |
109 | | -**On Linux (systemd):** |
110 | | -```bash |
111 | | -cd ~/.github-runner |
112 | | -sudo ./svc.sh install |
113 | | -sudo ./svc.sh start |
114 | | -sudo ./svc.sh status |
115 | | -``` |
116 | | - |
117 | | -**On macOS:** |
118 | | -```bash |
119 | | -cd ~/.github-runner |
120 | | -./svc.sh install |
121 | | -./svc.sh start |
122 | | -./svc.sh status |
123 | | -``` |
124 | | - |
125 | | -### Step 4: Verify in GitHub |
126 | | - |
127 | | -1. Go to your repository |
128 | | -2. Navigate to **Settings** → **Actions** → **Runners** |
129 | | -3. Your runner should appear with status **Idle** |
130 | | - |
131 | | -## Using the Workflow |
132 | | - |
133 | | -### Trigger Options |
134 | | - |
135 | | -#### Option 1: Manual Trigger (Recommended for Testing) |
136 | | -1. Go to **Actions** tab in your GitHub repository |
137 | | -2. Select **Local Android Build (Self-Hosted)** workflow |
138 | | -3. Click **Run workflow** → Select branch → Click **Run workflow** |
139 | | - |
140 | | -#### Option 2: Automatic on Push |
141 | | -The workflow triggers automatically on: |
142 | | -- All branch pushes |
143 | | -- Changes to `.github/workflows/local-android-build.yml` |
144 | | - |
145 | | -#### Option 3: Scheduled Build |
146 | | -To add a scheduled build (e.g., nightly), edit the workflow: |
147 | | - |
148 | | -```yaml |
149 | | -on: |
150 | | - schedule: |
151 | | - - cron: '0 2 * * *' # Run daily at 2 AM UTC |
152 | | -``` |
153 | | -
|
154 | | -### Monitoring Builds |
155 | | -
|
156 | | -1. Go to **Actions** tab |
157 | | -2. Click on the running workflow |
158 | | -3. View real-time logs |
159 | | -4. Check **Artifacts** after completion |
160 | | -
|
161 | | -### Release Artifacts |
162 | | -
|
163 | | -After a successful build: |
164 | | -1. Navigate to **Releases** page |
165 | | -2. Download the APK named: `app-release-{version}-build-{build_number}.apk` |
166 | | -3. Install on a device or emulator: |
167 | | - ```bash |
168 | | - adb install app-release-*.apk |
169 | | - ``` |
170 | | - |
171 | | -## Troubleshooting |
172 | | - |
173 | | -### Runner Shows "Offline" |
174 | | - |
175 | | -```bash |
176 | | -cd ~/.github-runner |
177 | | -
|
178 | | -# Check if service is running |
179 | | -sudo systemctl status actions.runner.* # Linux |
180 | | -launchctl list | grep actions # macOS |
181 | | -
|
182 | | -# Restart runner |
183 | | -sudo ./svc.sh stop |
184 | | -sudo ./svc.sh start |
185 | | -``` |
186 | | - |
187 | | -### Build Fails: ANDROID_HOME Not Found |
188 | | - |
189 | | -```bash |
190 | | -# Set ANDROID_HOME temporarily |
191 | | -export ANDROID_HOME=~/Android/Sdk |
192 | | -
|
193 | | -# Or add to your shell profile |
194 | | -echo 'export ANDROID_HOME=~/Android/Sdk' >> ~/.bashrc |
195 | | -source ~/.bashrc |
196 | | -``` |
197 | | - |
198 | | -### Build Fails: Java Version Wrong |
199 | | - |
200 | | -```bash |
201 | | -# Verify Java version |
202 | | -java -version |
203 | | -
|
204 | | -# Switch Java version (if multiple installed) |
205 | | -export JAVA_HOME=/usr/libexec/java_home -v 17 |
206 | | -``` |
207 | | - |
208 | | -### Build Takes Too Long |
209 | | - |
210 | | -- Consider upgrading CPU/RAM on your machine |
211 | | -- Close unrelated applications during builds |
212 | | -- Use SSD if available |
213 | | - |
214 | | -### APK Not Generated |
215 | | - |
216 | | -Check the build logs for: |
217 | | -1. Gradle compilation errors |
218 | | -2. Missing dependencies |
219 | | -3. Resource binding issues |
220 | | -4. Signing key problems |
221 | | - |
222 | | -## Storage Considerations |
223 | | - |
224 | | -- **APKs retained:** 14 days (configurable in workflow) |
225 | | -- **Storage used:** ~200-400 MB per APK |
226 | | -- **GitHub Free Tier:** 500 MB total artifact storage |
227 | | -- **GitHub Pro:** 2 GB total artifact storage |
228 | | - |
229 | | -Adjust retention-days in workflow if needed: |
230 | | -```yaml |
231 | | -retention-days: 7 # Keep for 7 days instead of 14 |
232 | | -``` |
233 | | - |
234 | | -## Security Best Practices |
235 | | - |
236 | | -1. **Keep runner machine secure** - It has access to your code |
237 | | -2. **Rotate PAT regularly** - Every 90 days recommended |
238 | | -3. **Limit runner labels** - Use specific labels to prevent accidental use |
239 | | -4. **Monitor runner logs** - Check for unauthorized access |
240 | | -5. **Use branch protection rules** - Require approvals before builds |
241 | | - |
242 | | -## Workflow vs EAS Builds Comparison |
243 | | - |
244 | | -| Feature | Local Build | EAS Build | |
245 | | -|---------|------------|-----------| |
246 | | -| **Cost** | Free (electricity) | $20/month | |
247 | | -| **Speed** | Depends on machine | ~5-10 mins | |
248 | | -| **Ease** | Requires setup | One-click | |
249 | | -| **Control** | Full | Limited | |
250 | | -| **Machine dependency** | Yes | No | |
251 | | -| **Cloud bandwidth** | No | Yes | |
252 | | -| **Build parallelization** | No | Yes (paid) | |
253 | | - |
254 | | -## Switching Between Workflows |
255 | | - |
256 | | -Both workflows can coexist: |
257 | | - |
258 | | -1. **Use Local Build** when you hit Expo.dev limits |
259 | | -2. **Use EAS Build** for full features or iOS builds |
260 | | -3. **Disable a workflow** by renaming it: |
261 | | - ``` |
262 | | - .github/workflows/eas-android-build.yml.disabled |
263 | | - ``` |
264 | | - |
265 | | -## Disabling the Workflow |
266 | | - |
267 | | -Simply disable the GitHub Actions workflow: |
268 | | -1. Go to **Settings** → **Actions** → **General** |
269 | | -2. Select **Disable all** or individual workflows |
270 | | - |
271 | | -## Support & Debugging |
272 | | - |
273 | | -For persistent issues: |
274 | | - |
275 | | -1. **Check runner logs:** |
276 | | - ```bash |
277 | | - cat ~/.github-runner/_diag/ |
278 | | - ``` |
279 | | - |
280 | | -2. **Check GitHub Actions logs** in your repository |
281 | | - |
282 | | -3. **Verify all prerequisites:** |
283 | | - ```bash |
284 | | - java -version |
285 | | - gradle -v |
286 | | - node -v |
287 | | - uname -m # Check architecture (x86_64, etc.) |
288 | | - ``` |
289 | | - |
290 | | -## Next Steps |
291 | | - |
292 | | -1. ✅ Install Android SDK and Java 17 |
293 | | -2. ✅ Create GitHub PAT |
294 | | -3. ✅ Set up runner on your machine |
295 | | -4. ✅ Test with manual workflow trigger |
296 | | -5. ✅ Monitor first build |
297 | | -6. ✅ Download and test APK on device |
0 commit comments