-
Notifications
You must be signed in to change notification settings - Fork 0
Development Setup
Complete guide for running and debugging the Zelara mobile app in different environments.
- Prerequisites
- Quick Start
- Development Workflows
- Understanding Metro Bundler
- Troubleshooting
- Build Configurations
- Node.js: >= 18.x
- npm or yarn
- JDK: 17 (configured in build.gradle:108-110)
- Android Studio: Latest stable version
- Android SDK: API 35 (compileSdk), API 34 (targetSdk), API 24+ (minSdk)
- Android NDK: 27.2.12479018
-
Install dependencies:
cd apps/mobile npm install -
Verify Android environment:
# Check ANDROID_HOME is set echo $ANDROID_HOME # Linux/Mac echo $env:ANDROID_HOME # Windows # Verify SDK installation adb --version
-
Connect device or start emulator:
# List connected devices adb devices # Or start Android Studio AVD Manager and launch an emulator
cd apps/mobile
npm run androidThis automatically:
- Starts Metro bundler
- Builds debug APK
- Installs APK on device/emulator
- Runs the app
IMPORTANT: When using Android Studio, Metro does NOT start automatically.
Step 1: Start Metro manually
cd apps/mobile
npm run startStep 2: Run app in Android Studio
- Click Run (
▶️ ) button - Or:
Run > Run 'app' - Or:
Shift + F10
Best for: Terminal-first developers, CI/CD scripts, automated testing
-
Start Metro + Build + Run (all-in-one):
cd apps/mobile npm run android -
Alternative: Separate Metro server (more control):
# Terminal 1: Start Metro cd apps/mobile npm run start # Terminal 2: Build and run npm run android
-
Install React Native Tools extension:
- Extension ID:
msjsdiag.vscode-react-native
- Extension ID:
-
Add
.vscode/launch.jsonconfiguration:{ "version": "0.2.0", "configurations": [ { "name": "Debug Android", "cwd": "${workspaceFolder}/apps/mobile", "type": "reactnative", "request": "launch", "platform": "android" } ] } -
Start debugging:
- Press
F5orRun > Start Debugging - Set breakpoints in TypeScript/JavaScript files
- Use Debug Console for evaluation
- Press
- Fast Refresh: Enabled by default - saves automatically reload
-
Manual reload: Shake device or press
Rtwice in Metro terminal -
Dev menu: Shake device or
Cmd+M(Mac) /Ctrl+M(Windows/Linux)
Best for: Native module development, UI inspection, Android-specific debugging
📖 Detailed Build Setup: See Android-Studio-Build-Setup.md for:
- Initial build configuration and troubleshooting
- Automating Metro bundler in run configuration
- Fixing Kotlin compilation errors
- Build verification and testing
Android Studio is an Android native IDE - it only handles:
- Gradle builds
- Native code compilation (Kotlin/Java)
- APK packaging and installation
It does NOT:
- Start JavaScript Metro bundler
- Bundle JS code in debug builds (by design: build.gradle:64)
Step 1: Start Metro Bundler
In VS Code integrated terminal or external terminal:
cd apps/mobile
npm run startYou should see:
###### ######
### #### #### ###
## ### ### ##
## ## ## ##
## ## ## ##
## ## ## ##
## ### ### ##
## #### #### ##
####### ########
Welcome to Metro v0.76.6
Fast - Scalable - Integrated
BUNDLER Metro is now listening on port 8081
Keep this terminal open while developing.
Step 2: Build & Run in Android Studio
- Open
apps/mobile/android/in Android Studio - Wait for Gradle sync to complete
- Select device/emulator from dropdown
- Click Run (
▶️ ) or pressShift + F10
What happens:
- Android Studio builds APK without bundled JS (debug mode)
- APK is installed on device
- App launches and connects to Metro at
localhost:8081 - Metro serves JavaScript bundle to the app
IMPORTANT: When connecting phone via USB, you MUST run this command every time:
# Forward port 8081 from device to computer
adb reverse tcp:8081 tcp:8081Why: USB-connected Android devices don't automatically forward localhost ports. Without this command:
- Metro runs on computer at
localhost:8081 - Device tries to connect to
localhost:8081on itself (not computer) - Result: "Unable to load script" error
When to run:
- ✅ Every time you connect phone via USB
- ✅ After unplugging and re-plugging USB cable
- ✅ After restarting adb (
adb kill-server/adb start-server) - ✅ If you see "Metro server not found" errors
Verify it's working:
# Should show the port forwarding
adb reverse --list
# Expected output:
# tcp:8081 tcp:8081Alternative - Skip Port Forwarding (Wireless Metro):
If you don't want to run adb reverse every time:
-
Find your computer's IP address:
# Windows ipconfig # Look for "Wireless LAN adapter Wi-Fi" → "IPv4 Address" # Mac/Linux ifconfig | grep inet
-
In the mobile app:
- Shake device to open Dev Menu
- Settings → Debug server host & port
- Enter:
192.168.x.x:8081(your computer's IP) - Reload app
-
Requirement: Phone and computer must be on same WiFi network
For wireless debugging, ensure device and computer are on same network.
Native Code (Kotlin/Java):
- Set breakpoints in
.ktor.javafiles - Use Android Studio debugger (works normally)
JavaScript/React Code:
- Ensure Metro is running
- In app, open Dev Menu: Shake device or
Cmd+M/Ctrl+M - Select "Open Debugger" → Opens Chrome DevTools or React Native DevTools
- Set breakpoints in Sources tab
Logcat for Crash Logs:
- View → Tool Windows → Logcat
- Filter by package:
ai.zelara.mobile - Look for
ReactNativeJStag for JS errors
Works the same as CLI workflow:
- Fast Refresh: Auto-reloads on save
-
Manual reload:
Rkey twice in Metro terminal - Clear cache and reload: Dev Menu → Reload
Metro is React Native's JavaScript bundler that:
- Transforms TypeScript/JSX → JavaScript
- Bundles all JS modules into single file
- Serves bundle to app via HTTP (development)
- Provides Fast Refresh (hot reload)
| Component | Role | When It Runs |
|---|---|---|
| Metro | Bundles JavaScript code |
npm run start or npm run android
|
| Gradle | Builds Android native code | Android Studio build or npm run android
|
Debug Build (build.gradle:64):
-
bundleInDebug: false- JS NOT bundled into APK - App expects Metro server at
localhost:8081 - Fast Refresh enabled
- Not optimized, includes dev tools
Release Build (build.gradle:65):
-
bundleInRelease: true- JS bundled into APK - Standalone APK, no Metro needed
- Minified, optimized, production-ready
Screenshot Reference: Your error message from 14:02:42
Cause: APK built without bundled JS, but Metro server not running.
Solution:
# Start Metro in separate terminal
cd apps/mobile
npm run startThen reload app:
- Shake device → Reload
- Or close and reopen app
ClassNotFoundException: Didn't find class "ai.zelara.mobile.MainApplication"
Cause: Build cache corruption or Gradle sync issue.
Solution:
cd apps/mobile/android
./gradlew clean
./gradlew assembleDebug
# Then rebuild in Android StudioCause: Native libraries not properly linked (New Architecture issue).
Solution:
-
Clean build:
cd apps/mobile/android ./gradlew clean rm -rf .gradle rm -rf app/build -
Rebuild dependencies:
cd apps/mobile rm -rf node_modules npm install -
Verify New Architecture is enabled: Check gradle.properties:35:
newArchEnabled=true -
Rebuild:
cd apps/mobile npm run android
Error: EADDRINUSE: address already in use :::8081
Solution:
Find and kill process:
# Linux/Mac
lsof -i :8081
kill -9 <PID>
# Windows
netstat -ano | findstr :8081
taskkill /PID <PID> /FOr use different port:
npm run start -- --port 8082Then update port forwarding:
adb reverse tcp:8082 tcp:8082Check Logcat:
- Android Studio → Logcat
- Filter:
package:ai.zelara.mobile - Look for
FATAL EXCEPTIONorReactNativeJSerrors
Common causes:
- Missing native dependencies
- Incorrect package name
- Permissions not granted (camera, storage)
Solution:
# Check permissions in AndroidManifest.xml
cat android/app/src/main/AndroidManifestTest.xml
# Reinstall clean build
npm run android -- --reset-cacheSymptoms: Code changes don't appear in app
Solution:
- Verify Metro is running and shows bundling output
-
Check Fast Refresh is enabled:
- Dev Menu → Settings → Ensure "Fast Refresh" toggled ON
-
Force reload:
- Press
Rtwice in Metro terminal - Or Dev Menu → Reload
- Press
-
Clear Metro cache:
npm run start -- --reset-cache
Problem: App can't reach Metro server on computer
Solution:
-
Ensure same network:
- Both device and computer on same WiFi
- No VPN blocking local network
-
Use computer's IP address:
- Dev Menu → Settings → Debug server host
- Enter:
192.168.x.x:8081(your computer's IP)
-
Check firewall:
- Allow incoming connections on port 8081
Error: "Failed to connect to Desktop" when scanning QR code
This is for Zelara Desktop ↔ Mobile device linking (port 8765), NOT Metro bundler (port 8081).
Checklist:
-
Desktop WebSocket server running:
# Check if port 8765 is listening netstat -an | findstr :8765 # Expected: TCP [IP]:8765 LISTENING
- If not listening: Open Zelara Desktop app → Click "Generate QR Code"
-
Windows Firewall rule created:
# Run as Administrator cd C:\Users\[YourUsername]\Documents\core\apps\desktop\scripts .\setup-firewall.ps1
- This allows inbound connections on port 8765
-
Both devices on same WiFi network:
# On Desktop (Windows) ipconfig # Note "Wireless LAN adapter Wi-Fi" → IPv4 Address (e.g., 172.25.99.241)
- Mobile WiFi settings: Check connected network name
- Must match Desktop's network (same SSID)
- Mobile IP should be in same subnet (e.g., 172.25.x.x)
-
Guest network / AP isolation:
- Some routers isolate devices on guest networks
- Try connecting to main WiFi network instead
- Or use Mobile Hotspot workaround (see below)
Quick Test - Mobile Hotspot:
If unable to get both on same network:
- Mobile: Enable Personal Hotspot
- Desktop: Connect to Mobile's hotspot WiFi
- Desktop: Open Zelara → Generate new QR code (new IP from hotspot)
- Mobile: Scan QR code → Should work!
Detailed Troubleshooting: See Desktop DEVICE-PAIRING-TROUBLESHOOTING.md
Understanding build.gradle
project.ext.react = [
enableHermes: true, // Use Hermes JS engine
bundleInDebug: false, // Don't bundle JS in debug APK
bundleInRelease: true, // Bundle JS in release APK
devDisabledInRelease: true
]When to change bundleInDebug:
-
Keep
false(default): Normal development with Hot Reload -
Set
true: Testing APK without Metro server (not recommended for dev)
Debug:
- Fast build time
- Metro-dependent
- Development features enabled
- APK:
app-debug.apk
Release:
- Optimized, minified
- Standalone (Metro not needed)
- ProGuard/R8 enabled
- Requires signing configuration
- APK:
app-release.apk
If you need to bundle JS manually (for testing release builds):
cd apps/mobile
npm run bundle:androidThis creates:
android/app/src/main/assets/index.android.bundle-
android/app/src/main/res/(assets)
Then build release APK:
cd android
./gradlew assembleReleaseOutput: android/app/build/outputs/apk/release/app-release.apk
- Always start Metro before running app in Android Studio
- Keep Metro terminal visible to see bundling logs
- Use Fast Refresh instead of full rebuild for JS changes
- Clean build when switching between branches
- Use
adb reversefor USB debugging - Check Logcat for crash details
- Use debug builds for development - Faster iteration
-
Clear Metro cache if seeing stale code:
npm run start -- --reset-cache -
Clean Gradle cache if build fails:
cd android && ./gradlew clean - Reduce emulator resources if computer is slow (lower RAM/CPU allocation)
When sharing setup issues:
- Share Metro terminal output (bundling logs)
- Share Logcat filtered for
ai.zelara.mobile - Include
adb devicesoutput - Mention which workflow you're using (VS Code CLI or Android Studio)
- React Native Debugging Docs
- Metro Configuration
- Android Studio User Guide
- Zelara Permissions Setup - Camera, storage permissions
Last Updated: 2025-02-24 React Native Version: 0.76.6 Target Android SDK: 35 (compileSdk), 34 (targetSdk)