From 6c55de9d6519cc5216d9f628c81baea6fb31b665 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ullrich=20Sch=C3=A4fer?= Date: Wed, 15 Apr 2026 01:22:50 +0200 Subject: [PATCH] Fix Android emulator dev server: use 10.0.2.2 instead of localhost MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Android emulator has its own network stack — localhost refers to the emulator, not the host. Use 10.0.2.2 (host loopback alias) on Android. Co-Authored-By: Claude Opus 4.6 (1M context) --- apps/mobile/app/login.tsx | 6 ++++-- apps/mobile/lib/server-config.ts | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/apps/mobile/app/login.tsx b/apps/mobile/app/login.tsx index 0c1df4c..947a171 100644 --- a/apps/mobile/app/login.tsx +++ b/apps/mobile/app/login.tsx @@ -1,5 +1,5 @@ import { useState } from "react"; -import { View, Text, TextInput, TouchableOpacity, StyleSheet, ActivityIndicator } from "react-native"; +import { View, Text, TextInput, TouchableOpacity, StyleSheet, ActivityIndicator, Platform } from "react-native"; import { router } from "expo-router"; import { setServerUrl, @@ -9,9 +9,11 @@ import { } from "../lib/server-config"; import { login } from "../lib/auth"; +const DEV_HOST = Platform.OS === "android" ? "10.0.2.2" : "localhost"; + export default function LoginScreen() { const [serverUrl, setServerUrlState] = useState( - __DEV__ ? "http://localhost:3000" : "https://trails.cool", + __DEV__ ? `http://${DEV_HOST}:3000` : "https://trails.cool", ); const [showCustomServer, setShowCustomServer] = useState(false); const [loading, setLoading] = useState(false); diff --git a/apps/mobile/lib/server-config.ts b/apps/mobile/lib/server-config.ts index a25c3d0..e7dc78b 100644 --- a/apps/mobile/lib/server-config.ts +++ b/apps/mobile/lib/server-config.ts @@ -1,8 +1,10 @@ +import { Platform } from "react-native"; import * as SecureStore from "expo-secure-store"; import { API_VERSION } from "@trails-cool/api"; const STORE_KEY_SERVER_URL = "server_url"; -const DEFAULT_SERVER_URL = __DEV__ ? "http://localhost:3000" : "https://trails.cool"; +const DEV_HOST = Platform.OS === "android" ? "10.0.2.2" : "localhost"; +const DEFAULT_SERVER_URL = __DEV__ ? `http://${DEV_HOST}:3000` : "https://trails.cool"; export interface DiscoveryResponse { apiVersion: string;