|
1 | | -# Android |
| 1 | +# DevCard Android |
2 | 2 |
|
3 | | -Android native project for the DevCard React Native mobile app. |
| 3 | +Native Android project for the DevCard React Native app. |
4 | 4 |
|
5 | | -## Prerequisites |
| 5 | +Use this folder for Android-specific Gradle builds, native configuration, emulator installs, and troubleshooting. For normal development, run commands from `apps/mobile` unless a command below says otherwise. |
6 | 6 |
|
7 | | -- Node.js `>= 22.11.0` |
8 | | -- Android Studio with Android SDK and emulator installed |
9 | | -- Java version supported by the installed Android Gradle Plugin |
10 | | -- Dependencies installed from `apps/mobile` with npm |
11 | | - |
12 | | -## Run On Android |
| 7 | +## Quick Start |
13 | 8 |
|
14 | | -From `apps/mobile`, start Metro in one terminal: |
| 9 | +Start Metro from `apps/mobile`: |
15 | 10 |
|
16 | 11 | ```cmd |
17 | 12 | npx react-native start --reset-cache |
18 | 13 | ``` |
19 | 14 |
|
20 | | -In a second terminal, run the app: |
| 15 | +Open a second terminal and run the Android app: |
21 | 16 |
|
22 | 17 | ```cmd |
23 | 18 | cd /d D:\DC\apps\mobile |
24 | 19 | npx react-native run-android -- --active-arch-only |
25 | 20 | ``` |
26 | 21 |
|
27 | | -`--active-arch-only` keeps local emulator builds faster by building only the active emulator/device architecture. |
| 22 | +`--active-arch-only` builds only the connected emulator/device architecture, which is much faster during local development. |
28 | 23 |
|
29 | | -## Gradle Commands |
| 24 | +## Requirements |
| 25 | + |
| 26 | +- Node.js `>= 22.11.0` |
| 27 | +- Android Studio with Android SDK and emulator support |
| 28 | +- Java version compatible with the Android Gradle Plugin used by this project |
| 29 | +- npm dependencies installed from `apps/mobile` |
| 30 | +- An Android emulator running, or a physical device connected with USB debugging enabled |
30 | 31 |
|
31 | | -Run these from `apps/mobile/android`: |
| 32 | +Install mobile dependencies from `apps/mobile`: |
32 | 33 |
|
33 | 34 | ```cmd |
34 | | -gradlew.bat app:packageDebug --stacktrace -PreactNativeArchitectures=x86_64 |
| 35 | +npm install --legacy-peer-deps |
| 36 | +``` |
| 37 | + |
| 38 | +## Useful Gradle Commands |
| 39 | + |
| 40 | +Run these from `apps/mobile/android`. |
| 41 | + |
| 42 | +Build a debug APK: |
| 43 | + |
| 44 | +```cmd |
| 45 | +gradlew.bat app:packageDebug -PreactNativeArchitectures=x86_64 |
35 | 46 | ``` |
36 | 47 |
|
| 48 | +Install the debug build on a connected emulator/device: |
| 49 | + |
37 | 50 | ```cmd |
38 | 51 | gradlew.bat app:installDebug -PreactNativeArchitectures=x86_64 |
39 | 52 | ``` |
40 | 53 |
|
41 | | -The project currently sets `reactNativeArchitectures=x86_64` in `gradle.properties` for faster local Windows emulator builds. Use a CLI override when building for another device architecture, for example: |
| 54 | +Get detailed output for a failing build: |
| 55 | + |
| 56 | +```cmd |
| 57 | +gradlew.bat app:packageDebug --stacktrace -PreactNativeArchitectures=x86_64 |
| 58 | +``` |
| 59 | + |
| 60 | +## Architecture Builds |
| 61 | + |
| 62 | +`gradle.properties` currently sets: |
| 63 | + |
| 64 | +```properties |
| 65 | +reactNativeArchitectures=x86_64 |
| 66 | +``` |
| 67 | + |
| 68 | +This keeps Windows emulator builds smaller and faster. Override it when targeting another device architecture: |
42 | 69 |
|
43 | 70 | ```cmd |
44 | 71 | gradlew.bat app:packageDebug -PreactNativeArchitectures=arm64-v8a |
45 | 72 | ``` |
46 | 73 |
|
| 74 | +Use all common Android ABIs only when needed: |
| 75 | + |
| 76 | +```cmd |
| 77 | +gradlew.bat app:packageDebug -PreactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64 |
| 78 | +``` |
| 79 | + |
47 | 80 | ## Troubleshooting |
48 | 81 |
|
| 82 | +### Metro Watches `D:\packages` |
| 83 | + |
49 | 84 | If Metro reports `ENOENT` for `D:\packages`, check `apps/mobile/metro.config.js`. The monorepo root should resolve to `D:\DC`, not `D:\`. |
50 | 85 |
|
51 | | -If Gradle fails at `:app:packageDebug`, rerun with `--stacktrace`: |
| 86 | +### Gradle Fails At `:app:packageDebug` |
| 87 | + |
| 88 | +Rerun the package task with `--stacktrace` so the real error appears: |
52 | 89 |
|
53 | 90 | ```cmd |
54 | 91 | gradlew.bat app:packageDebug --stacktrace -PreactNativeArchitectures=x86_64 |
55 | 92 | ``` |
56 | 93 |
|
57 | | -If Android builds are very slow, avoid building all ABIs during local development. Use `--active-arch-only` through React Native CLI or pass `-PreactNativeArchitectures=x86_64` to Gradle. |
| 94 | +### Builds Are Slow |
| 95 | + |
| 96 | +Use one of these faster local options: |
| 97 | + |
| 98 | +- `npx react-native run-android -- --active-arch-only` |
| 99 | +- `gradlew.bat app:packageDebug -PreactNativeArchitectures=x86_64` |
| 100 | + |
| 101 | +Avoid building every ABI unless you are preparing a broader test or release build. |
| 102 | + |
| 103 | +### Windows Long Path Errors |
58 | 104 |
|
59 | 105 | If Windows reports paths longer than 260 characters, enable long paths from an Administrator PowerShell: |
60 | 106 |
|
61 | 107 | ```powershell |
62 | 108 | New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force |
63 | 109 | ``` |
| 110 | + |
| 111 | +Restart the terminal after changing this setting. |
0 commit comments