@ -1,4 +1,4 @@
# Android Custom API IP Configuration
# Mobile Custom API IP Configuration
**Author**: Matthew Raymer
**Author**: Matthew Raymer
**Date**: 2025-01-27
**Date**: 2025-01-27
@ -10,61 +10,85 @@ When deploying TimeSafari to physical Android devices during development, you ma
## Problem
## Problem
During Android development:
During mobile development:
- **Emulator** : Uses `10.0.2.2:3000` to access host machine's localhost (default)
- **Android Emulator** : Uses `10.0.2.2:3000` to access host machine's localhost (Android emulator default)
- **Physical Device** : Cannot access `localhost` or `10.0.2.2` - needs actual IP address
- **iOS Simulator** : Uses `localhost:3000` to access host machine's localhost (iOS simulator default)
- **Physical Devices** : Cannot access `localhost` or `10.0.2.2` - needs actual IP address for network access
## Solution
## Solution
The Android build system defaults to `10.0.2.2:3000` for emulator development and supports specifying a custom IP address for the claim API server when building for physical devices.
The mobile build system uses platform-appropriate defaults and supports specifying a custom IP address for the claim API server when building for physical devices:
- **Android** : Defaults to `10.0.2.2:3000` for emulator development
- **iOS** : Uses Capacitor default (`localhost:3000`) for simulator development
## Usage
## Usage
### Command Line Usage
### Command Line Usage
```bash
```bash
# Default behavior (uses 10.0.2.2 for emulator)
# Android - Default behavior (uses 10.0.2.2 for emulator)
./scripts/build-android.sh --dev
./scripts/build-android.sh --dev
# Custom IP for physical device
# Android - Custom IP for physical device
./scripts/build-android.sh --dev --api-ip 192.168.1.100
./scripts/build-android.sh --dev --api-ip 192.168.1.100
# iOS - Default behavior (uses localhost for simulator)
./scripts/build-ios.sh --dev
# iOS - Custom IP for physical device
./scripts/build-ios.sh --dev --api-ip 192.168.1.100
# Test environment with custom IP
# Test environment with custom IP
./scripts/build-android.sh --test --api-ip 192.168.1.100
./scripts/build-android.sh --test --api-ip 192.168.1.100
./scripts/build-ios.sh --test --api-ip 192.168.1.100
# Build and auto-run with custom IP
# Build and auto-run with custom IP
./scripts/build-android.sh --dev --api-ip 192.168.1.100 --auto-run
./scripts/build-android.sh --dev --api-ip 192.168.1.100 --auto-run
./scripts/build-ios.sh --dev --api-ip 192.168.1.100 --auto-run
```
```
### NPM Scripts
### NPM Scripts
```bash
```bash
# Default development build (uses 10.0.2.2 for emulator)
# Android - Default development build (uses 10.0.2.2 for emulator)
npm run build:android:dev
npm run build:android:dev
# Development build with custom IP (requires IP parameter)
# Android - Development build with custom IP (requires IP parameter)
npm run build:android:dev:custom 192.168.1.100
npm run build:android:dev:custom 192.168.1.100
# Test build with custom IP (requires IP parameter)
# iOS - Default development build (uses localhost for simulator)
npm run build:ios:dev
# iOS - Development build with custom IP (requires IP parameter)
npm run build:ios:dev:custom 192.168.1.100
# Test builds with custom IP (requires IP parameter)
npm run build:android:test:custom 192.168.1.100
npm run build:android:test:custom 192.168.1.100
npm run build:ios:test:custom 192.168.1.100
# Development build + auto-run with custom IP
# Development build + auto-run with custom IP
npm run build:android:dev:run:custom 192.168.1.100
npm run build:android:dev:run:custom 192.168.1.100
npm run build:ios:dev:run:custom 192.168.1.100
# Test build + auto-run with custom IP
# Test build + auto-run with custom IP
npm run build:android:test:run:custom 192.168.1.100
npm run build:android:test:run:custom 192.168.1.100
npm run build:ios:test:run:custom 192.168.1.100
```
```
## Examples
## Examples
### Scenario 1: Development on Emulator (Default)
### Scenario 1: Development on Simulator/ Emulator (Default)
```bash
```bash
# Default behavior - uses 10.0.2.2 for emulator
# Android - Default behavior - uses 10.0.2.2 for emulator
npm run build:android:dev
npm run build:android:dev
# Build and immediately run on emulator
# iOS - Default behavior - uses localhost for simulator
npm run build:ios:dev
# Build and immediately run on simulator/emulator
npm run build:android:dev:run
npm run build:android:dev:run
npm run build:ios:dev:run
```
```
### Scenario 2: Development on Physical Device
### Scenario 2: Development on Physical Device
@ -72,9 +96,11 @@ npm run build:android:dev:run
```bash
```bash
# Your development server is running on 192.168.1.50:3000
# Your development server is running on 192.168.1.50:3000
npm run build:android:dev:custom 192.168.1.50
npm run build:android:dev:custom 192.168.1.50
npm run build:ios:dev:custom 192.168.1.50
# Build and immediately run on device
# Build and immediately run on device
npm run build:android:dev:run:custom 192.168.1.50
npm run build:android:dev:run:custom 192.168.1.50
npm run build:ios:dev:run:custom 192.168.1.50
```
```
### Scenario 3: Testing on Physical Device
### Scenario 3: Testing on Physical Device
@ -82,20 +108,23 @@ npm run build:android:dev:run:custom 192.168.1.50
```bash
```bash
# Your test server is running on 192.168.1.75:3000
# Your test server is running on 192.168.1.75:3000
npm run build:android:test:custom 192.168.1.75
npm run build:android:test:custom 192.168.1.75
npm run build:ios:test:custom 192.168.1.75
# Build and immediately run on device
# Build and immediately run on device
npm run build:android:test:run:custom 192.168.1.75
npm run build:android:test:run:custom 192.168.1.75
npm run build:ios:test:run:custom 192.168.1.75
```
```
### Scenario 4: Direct Script Usage
### Scenario 4: Direct Script Usage
```bash
```bash
# Default behavior (em ulator)
# Default behavior (uses p latf orm-appropriate defaults )
./scripts/build-android.sh --dev --studio
./scripts/build-android.sh --dev --studio
./scripts/build-ios.sh --dev --studio
# Custom IP for physical device
# Custom IP for physical device
./scripts/build-android.sh --dev --api-ip 192.168.1.100 --studio
./scripts/build-android.sh --dev --api-ip 192.168.1.100 --studio
./scripts/build-android.sh --test --api-ip 192.168.1.100 --apk
./scripts/build-ios.sh --dev --api-ip 192.168.1.100 --studio
```
```
## How It Works
## How It Works
@ -104,18 +133,23 @@ npm run build:android:test:run:custom 192.168.1.75
The build system handles API server configuration as follows:
The build system handles API server configuration as follows:
1. **Default behavior** : Uses `http://10.0.2.2:3000` for emulator development
1. **Android default** : Uses Android emulator default (`http://10.0.2.2:3000`)
2. **Custom IP specified** : Overrides with `http://<custom-ip>:3000` for physical device development
2. **iOS default** : Uses Capacitor default (`http://localhost:3000`)
3. **Maintains other APIs** : Image and Partner APIs remain at production URLs
3. **Custom IP specified** : Overrides with `http://<custom-ip>:3000` for physical device development
4. **Logs the configuration** : Shows which IP is being used in build logs
4. **Maintains other APIs** : Image and Partner APIs remain at production URLs
5. **Logs the configuration** : Shows which IP is being used in build logs
### Build Process
### Build Process
```bash
```bash
# Development mode with default IP (10.0.2.2)
# Development mode with Android emulator default (10.0.2.2)
export VITE_DEFAULT_ENDORSER_API_SERVER="http://10.0.2.2:3000"
export VITE_DEFAULT_ENDORSER_API_SERVER="http://10.0.2.2:3000"
npm run build:capacitor -- --mode development
npm run build:capacitor -- --mode development
# Development mode with iOS simulator default (localhost)
export VITE_DEFAULT_ENDORSER_API_SERVER="http://localhost:3000"
npm run build:capacitor -- --mode development
# Development mode with custom IP
# Development mode with custom IP
export VITE_DEFAULT_ENDORSER_API_SERVER="http://192.168.1.100:3000"
export VITE_DEFAULT_ENDORSER_API_SERVER="http://192.168.1.100:3000"
npm run build:capacitor -- --mode development
npm run build:capacitor -- --mode development
@ -123,7 +157,8 @@ npm run build:capacitor -- --mode development
### Default Behavior
### Default Behavior
- **No `--api-ip` specified** : Uses default emulator IP (`10.0.2.2:3000`)
- **Android (no `--api-ip`)** : Uses Android emulator default (`10.0.2.2:3000`)
- **iOS (no `--api-ip`)** : Uses Capacitor default (`localhost:3000`)
- **Custom IP specified** : Uses provided IP address for physical device development
- **Custom IP specified** : Uses provided IP address for physical device development
- **Invalid IP format** : Build will fail with clear error message
- **Invalid IP format** : Build will fail with clear error message
- **Network unreachable** : App will show connection errors at runtime
- **Network unreachable** : App will show connection errors at runtime