Add custom API IP support for Android physical device development

Implement --api-ip parameter for Android builds with smart defaults:
- Defaults to 10.0.2.2 for emulator development when no IP specified
- Supports custom IP for physical device development
- Added npm scripts for common use cases (dev:custom, test:custom)
- Updated help documentation with usage examples
- Created comprehensive documentation with troubleshooting guide

Usage:
  ./scripts/build-android.sh --dev                    # Default 10.0.2.2
  ./scripts/build-android.sh --dev --api-ip 192.168.1.100  # Custom IP
This commit is contained in:
Matthew Raymer
2025-08-05 10:26:38 +00:00
parent b681905abd
commit 1d6418b02c
3 changed files with 320 additions and 5 deletions

View File

@@ -60,12 +60,16 @@ SYNC_ONLY=false
ASSETS_ONLY=false
DEPLOY_APP=false
AUTO_RUN=false
CUSTOM_API_IP=""
# Function to parse Android-specific arguments
parse_android_args() {
local args=("$@")
local i=0
for arg in "${args[@]}"; do
while [ $i -lt ${#args[@]} ]; do
local arg="${args[$i]}"
case $arg in
--dev|--development)
BUILD_MODE="development"
@@ -106,6 +110,18 @@ parse_android_args() {
--auto-run)
AUTO_RUN=true
;;
--api-ip)
if [ $((i + 1)) -lt ${#args[@]} ]; then
CUSTOM_API_IP="${args[$((i + 1))]}"
i=$((i + 1)) # Skip the next argument
else
log_error "Error: --api-ip requires an IP address"
exit 1
fi
;;
--api-ip=*)
CUSTOM_API_IP="${arg#*=}"
;;
-h|--help)
print_android_usage
exit 0
@@ -117,6 +133,7 @@ parse_android_args() {
log_warn "Unknown argument: $arg"
;;
esac
i=$((i + 1))
done
}
@@ -138,6 +155,7 @@ print_android_usage() {
echo " --assets Generate assets only"
echo " --deploy Deploy APK to connected device"
echo " --auto-run Auto-run app after build"
echo " --api-ip <ip> Custom IP address for claim API (defaults to 10.0.2.2)"
echo ""
echo "Common Options:"
echo " -h, --help Show this help message"
@@ -151,6 +169,8 @@ print_android_usage() {
echo " $0 --clean # Clean only"
echo " $0 --sync # Sync only"
echo " $0 --deploy # Build and deploy to device"
echo " $0 --dev # Dev build with default 10.0.2.2"
echo " $0 --dev --api-ip 192.168.1.100 # Dev build with custom API IP"
echo ""
}
@@ -166,10 +186,17 @@ log_info "Build type: $BUILD_TYPE"
# Setup environment for Capacitor build
setup_build_env "capacitor"
# Override API server for Android emulator development
# Override API server for Android development
if [ "$BUILD_MODE" = "development" ]; then
export VITE_DEFAULT_ENDORSER_API_SERVER="http://10.0.2.2:3000"
log_debug "Android development mode: Using 10.0.2.2 for emulator, production for Image/Partner APIs"
if [ -n "$CUSTOM_API_IP" ]; then
# Use custom IP for physical device development
export VITE_DEFAULT_ENDORSER_API_SERVER="http://${CUSTOM_API_IP}:3000"
log_info "Android development mode: Using custom IP ${CUSTOM_API_IP} for physical device"
else
# Use default emulator IP (10.0.2.2) for Android development
export VITE_DEFAULT_ENDORSER_API_SERVER="http://10.0.2.2:3000"
log_debug "Android development mode: Using default 10.0.2.2 for emulator"
fi
fi
# Setup application directories