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#
- Enable Developer Options on your Android device (Settings > About Phone > Tap Build Number 7 times).
- Enable USB Debugging in Developer Options.
- 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.
-
Connect your Android device via USB.
-
Run the following command in your terminal to forward the HTTPS port:
adb reverse tcp:443 tcp:443Troubleshooting: "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:- Run:
adb reverse tcp:3000 tcp:443 - 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) - Run:
-
Run the Flutter app:
flutter run -d <device-id>
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.
- Open
lib/services/api_client.dart. - Change the
baseUrldefault value:// In lib/services/api_client.dart this.baseUrl = 'https://10.0.2.2/api', // For Emulator // this.baseUrl = 'https://localhost/api', // Default - 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.
- Find your computer's local IP address (e.g.,
192.168.1.5). - Open
lib/services/api_client.dartand updatebaseUrl:this.baseUrl = 'https://192.168.1.5/api', - Important: You must also update
lib/services/dev_http_client_io.dartto trust this specific IP address in thebadCertificateCallback:return host == 'localhost' || host == '127.0.0.1' || host == '192.168.1.5'; - Ensure your computer's firewall allows incoming connections on port 443 (or your server port).