diff --git a/BUILDING.md b/BUILDING.md index cdbfb565..747f824d 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -1721,20 +1721,10 @@ VITE_APP_SERVER=https://timesafari.app fi ``` -2. **Platform-Specific Overrides** +2. **Environment File Loading** ```bash - # scripts/build-android.sh - if [ "$BUILD_MODE" = "development" ]; then - export VITE_DEFAULT_ENDORSER_API_SERVER="http://10.0.2.2:3000" - export VITE_DEFAULT_PARTNER_API_SERVER="http://10.0.2.2:3000" - fi - ``` - -3. **Environment File Loading** - - ```bash - # scripts/build-web.sh + # scripts/build-web.sh, build-android.sh, build-ios.sh, build-electron.sh local env_file=".env.$BUILD_MODE" # .env.development, .env.test, .env.production if [ -f "$env_file" ]; then load_env_file "$env_file" @@ -1746,6 +1736,18 @@ VITE_APP_SERVER=https://timesafari.app fi ``` +3. **Platform-Specific Overrides** + + These run last so the platform address wins over the `.env` files. + + ```bash + # scripts/build-android.sh + if [ "$BUILD_MODE" = "development" ]; then + export VITE_DEFAULT_ENDORSER_API_SERVER="http://10.0.2.2:3000" + export VITE_DEFAULT_PARTNER_API_SERVER="http://10.0.2.2:3000" + fi + ``` + 4. **Application Usage** ```typescript diff --git a/CHANGELOG.md b/CHANGELOG.md index 78b263f8..90e10691 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 revocation to stop the texts - Notification debug panel action to mint and upload a push-channel alertSearch authorization, built on the same batch minter as the SMS channel +### Fixed +- Native build scripts set NODE_ENV, so `import.meta.env.DEV` matches the build + mode instead of always reporting a production build +- Android and iOS development builds keep their emulator and `--api-ip` API + addresses, which the `.env` files had been overwriting ## [1.3.8] - 2026 diff --git a/doc/android-physical-device-guide.md b/doc/android-physical-device-guide.md index 96c27f33..bb74adab 100644 --- a/doc/android-physical-device-guide.md +++ b/doc/android-physical-device-guide.md @@ -128,19 +128,29 @@ Your Android device and computer **must be on the same Wi-Fi network** for the d ### Step 3: Configure API Endpoints -Create or edit `.env.development` with your computer's IP: +Pass your computer's IP to the build with `--api-ip`. The build script points +the claim and partner APIs at that address: ```bash -# .env.development - for physical device testing -VITE_DEFAULT_ENDORSER_API_SERVER=http://192.168.1.100:3000 -VITE_DEFAULT_PARTNER_API_SERVER=http://192.168.1.100:3000 +npm run build:android:dev -- --api-ip 192.168.1.100 +``` + +**Important**: Replace `192.168.1.100` with your actual IP address. + +Without `--api-ip`, a development build uses `10.0.2.2:3000`, which reaches the +host machine from an emulator but not from a physical device. + +The build script applies `--api-ip` after loading `.env.development`, so the +flag wins for the claim and partner APIs. Other addresses come from that file, +which development web builds share: + +```bash +# .env.development VITE_DEFAULT_IMAGE_API_SERVER=https://test-image-api.timesafari.app VITE_DEFAULT_NOTIFY_API_SERVER=https://test-notify-api.timesafari.app VITE_APP_SERVER=http://192.168.1.100:8080 ``` -**Important**: Replace `192.168.1.100` with your actual IP address. - ### Step 4: Start Your Local Server If testing against local API servers, ensure they're accessible from the network: diff --git a/scripts/build-android.sh b/scripts/build-android.sh index 1c6e1350..11436bd6 100755 --- a/scripts/build-android.sh +++ b/scripts/build-android.sh @@ -492,21 +492,6 @@ log_info "Build type: $BUILD_TYPE" # Setup environment for Capacitor build setup_build_env "capacitor" "$BUILD_MODE" -# Override API servers for Android development -if [ "$BUILD_MODE" = "development" ]; then - if [ -n "$CUSTOM_API_IP" ]; then - # Use custom IP for physical device development - export VITE_DEFAULT_ENDORSER_API_SERVER="http://${CUSTOM_API_IP}:3000" - export VITE_DEFAULT_PARTNER_API_SERVER="http://${CUSTOM_API_IP}:3000" - log_info "Android development mode: Using custom IP ${CUSTOM_API_IP} for physical device" - else - # Use Android emulator IP (10.0.2.2) for Android development - export VITE_DEFAULT_ENDORSER_API_SERVER="http://10.0.2.2:3000" - export VITE_DEFAULT_PARTNER_API_SERVER="http://10.0.2.2:3000" - log_debug "Android development mode: Using 10.0.2.2 for emulator" - fi -fi - # Setup application directories setup_app_directories @@ -523,6 +508,21 @@ if [ -f ".env" ]; then load_env_file ".env" fi +# Override API servers for Android development +if [ "$BUILD_MODE" = "development" ]; then + if [ -n "$CUSTOM_API_IP" ]; then + # Use custom IP for physical device development + export VITE_DEFAULT_ENDORSER_API_SERVER="http://${CUSTOM_API_IP}:3000" + export VITE_DEFAULT_PARTNER_API_SERVER="http://${CUSTOM_API_IP}:3000" + log_info "Android development mode: Using custom IP ${CUSTOM_API_IP} for physical device" + else + # Use Android emulator IP (10.0.2.2) for Android development + export VITE_DEFAULT_ENDORSER_API_SERVER="http://10.0.2.2:3000" + export VITE_DEFAULT_PARTNER_API_SERVER="http://10.0.2.2:3000" + log_debug "Android development mode: Using 10.0.2.2 for emulator" + fi +fi + # Handle clean-only mode if [ "$CLEAN_ONLY" = true ]; then log_info "Clean-only mode: cleaning build artifacts" diff --git a/scripts/build-ios.sh b/scripts/build-ios.sh index 0d8aba4f..0886c0ce 100755 --- a/scripts/build-ios.sh +++ b/scripts/build-ios.sh @@ -320,14 +320,6 @@ log_info "Build type: $BUILD_TYPE" # Setup environment for Capacitor build setup_build_env "capacitor" "$BUILD_MODE" -# Override API servers for iOS development when custom IP is specified -if [ "$BUILD_MODE" = "development" ] && [ -n "$CUSTOM_API_IP" ]; then - # Use custom IP for physical device development - export VITE_DEFAULT_ENDORSER_API_SERVER="http://${CUSTOM_API_IP}:3000" - export VITE_DEFAULT_PARTNER_API_SERVER="http://${CUSTOM_API_IP}:3000" - log_info "iOS development mode: Using custom IP ${CUSTOM_API_IP} for physical device" -fi - # Setup application directories setup_app_directories @@ -344,6 +336,14 @@ if [ -f ".env" ]; then load_env_file ".env" fi +# Override API servers for iOS development when custom IP is specified +if [ "$BUILD_MODE" = "development" ] && [ -n "$CUSTOM_API_IP" ]; then + # Use custom IP for physical device development + export VITE_DEFAULT_ENDORSER_API_SERVER="http://${CUSTOM_API_IP}:3000" + export VITE_DEFAULT_PARTNER_API_SERVER="http://${CUSTOM_API_IP}:3000" + log_info "iOS development mode: Using custom IP ${CUSTOM_API_IP} for physical device" +fi + # Validate iOS environment validate_ios_environment diff --git a/scripts/common.sh b/scripts/common.sh index ac1e3858..a7cf7c16 100755 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -183,6 +183,16 @@ setup_build_env() { export VITE_GIT_HASH="$git_hash" log_debug "Set VITE_GIT_HASH=$git_hash" + # Vite derives import.meta.env.DEV/PROD from NODE_ENV, not from --mode. + # Without this, every native build reports DEV=false and loads the + # production .env file in vite.config.common.mts. + case "$build_mode" in + "production") export NODE_ENV=production ;; + "test") export NODE_ENV=test ;; + *) export NODE_ENV=development ;; + esac + log_debug "Set NODE_ENV=$NODE_ENV" + case $build_type in "capacitor") export VITE_PLATFORM=capacitor