# Android Debugging Guide for Localhost Debugging the Toadist Android app with a local server requires specific network configuration because `localhost` on the Android device refers to the device itself, not your development machine. ## Prerequisites 1. **Enable Developer Options** on your Android device (Settings > About Phone > Tap Build Number 7 times). 2. **Enable USB Debugging** in Developer Options. 3. **Install ADB** (Android Debug Bridge) on your computer. ## Method 1: USB Connection (Recommended) This is the easiest method as it allows you to use `https://localhost` on the device without changing any code or certificates. 1. Connect your Android device via USB. 2. Run the following command in your terminal to forward the HTTPS port: ```bash adb reverse tcp:443 tcp:443 ``` > **Troubleshooting: "Permission denied"** > If you see `adb: error: cannot bind listener: Permission denied`, your Android device restricts binding to ports below 1024 (like 443). > **Solution:** Use a higher port on the device (e.g., 3000) and map it to 443 on your computer: > 1. Run: `adb reverse tcp:3000 tcp:443` > 2. Update `lib/services/api_client.dart`: `baseUrl = 'https://localhost:3000/api';` *(If your server runs on a different port, e.g., 8080, run `adb reverse tcp:8080 tcp:8080`)* 3. Run the Flutter app: ```bash flutter run -d ``` The app will now be able to connect to `https://localhost/api` just like your computer does. ## Method 2: Android Emulator The Android Emulator uses a special IP address `10.0.2.2` to refer to the host computer's loopback interface. 1. Open `lib/services/api_client.dart`. 2. Change the `baseUrl` default value: ```dart // In lib/services/api_client.dart this.baseUrl = 'https://10.0.2.2/api', // For Emulator // this.baseUrl = 'https://localhost/api', // Default ``` 3. Run the app on the emulator. *Note: We have updated `DevHttpClient` to trust certificates from `10.0.2.2` automatically.* ## Method 3: Wi-Fi Connection (Advanced) If you cannot use USB, you must use your computer's LAN IP address. 1. Find your computer's local IP address (e.g., `192.168.1.5`). 2. Open `lib/services/api_client.dart` and update `baseUrl`: ```dart this.baseUrl = 'https://192.168.1.5/api', ``` 3. **Important:** You must also update `lib/services/dev_http_client_io.dart` to trust this specific IP address in the `badCertificateCallback`: ```dart return host == 'localhost' || host == '127.0.0.1' || host == '192.168.1.5'; ``` 4. Ensure your computer's firewall allows incoming connections on port 443 (or your server port).