From 32f589b86697267e362d28a1d8569131c99a57c6 Mon Sep 17 00:00:00 2001 From: Matthew Raymer Date: Tue, 5 Aug 2025 09:08:50 +0000 Subject: [PATCH] Fix Android emulator API connectivity with cleaner build script approach - Move Android-specific API server logic from common.sh to build-android.sh - Remove unnecessary ANDROID_BUILD environment variable - Set localhost:3000 as default in common.sh for all Capacitor builds - Override to 10.0.2.2:3000 specifically in build-android.sh for Android development - Fix execution order issue where common.sh ran before ANDROID_BUILD was set - Maintain proper separation: Android emulator uses 10.0.2.2, iOS simulator uses localhost --- android/app/src/main/assets/capacitor.config.json | 5 +++-- android/build.gradle | 2 +- capacitor.config.json | 5 +++-- scripts/build-android.sh | 6 ++++++ scripts/common.sh | 4 +++- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/android/app/src/main/assets/capacitor.config.json b/android/app/src/main/assets/capacitor.config.json index e0f25d83..594ebca3 100644 --- a/android/app/src/main/assets/capacitor.config.json +++ b/android/app/src/main/assets/capacitor.config.json @@ -57,13 +57,14 @@ ] }, "android": { - "allowMixedContent": false, + "allowMixedContent": true, "captureInput": true, "webContentsDebuggingEnabled": false, "allowNavigation": [ "*.timesafari.app", "*.jsdelivr.net", - "api.endorser.ch" + "api.endorser.ch", + "10.0.2.2:3000" ] }, "electron": { diff --git a/android/build.gradle b/android/build.gradle index 5a959f82..858b0bc0 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -7,7 +7,7 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:8.11.1' + classpath 'com.android.tools.build:gradle:8.12.0' classpath 'com.google.gms:google-services:4.4.0' // NOTE: Do not place your application dependencies here; they belong diff --git a/capacitor.config.json b/capacitor.config.json index 08573136..863ae475 100644 --- a/capacitor.config.json +++ b/capacitor.config.json @@ -57,13 +57,14 @@ ] }, "android": { - "allowMixedContent": false, + "allowMixedContent": true, "captureInput": true, "webContentsDebuggingEnabled": false, "allowNavigation": [ "*.timesafari.app", "*.jsdelivr.net", - "api.endorser.ch" + "api.endorser.ch", + "10.0.2.2:3000" ] }, "electron": { diff --git a/scripts/build-android.sh b/scripts/build-android.sh index bf3df09a..1e3c4bed 100755 --- a/scripts/build-android.sh +++ b/scripts/build-android.sh @@ -166,6 +166,12 @@ log_info "Build type: $BUILD_TYPE" # Setup environment for Capacitor build setup_build_env "capacitor" +# Override API server for Android emulator 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" +fi + # Setup application directories setup_app_directories diff --git a/scripts/common.sh b/scripts/common.sh index cb658998..7b106c8d 100755 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -197,10 +197,12 @@ setup_build_env() { # Set API server environment variables based on build mode if [ "$BUILD_MODE" = "development" ]; then + # For Capacitor development, use localhost by default + # Android builds will override this in build-android.sh export VITE_DEFAULT_ENDORSER_API_SERVER="http://localhost:3000" + log_debug "Development mode: Using localhost for Endorser API, production for Image/Partner APIs" export VITE_DEFAULT_IMAGE_API_SERVER="https://image-api.timesafari.app" export VITE_DEFAULT_PARTNER_API_SERVER="https://partner-api.endorser.ch" - log_debug "Development mode: Using localhost for Endorser API, production for Image/Partner APIs" elif [ "$BUILD_MODE" = "test" ]; then export VITE_DEFAULT_ENDORSER_API_SERVER="https://test-api.endorser.ch" export VITE_DEFAULT_IMAGE_API_SERVER="https://image-api.timesafari.app"