A todo and personal organisation app
1# Android Debugging Guide for Localhost
2
3Debugging 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.
4
5## Prerequisites
61. **Enable Developer Options** on your Android device (Settings > About Phone > Tap Build Number 7 times).
72. **Enable USB Debugging** in Developer Options.
83. **Install ADB** (Android Debug Bridge) on your computer.
9
10## Method 1: USB Connection (Recommended)
11This is the easiest method as it allows you to use `https://localhost` on the device without changing any code or certificates.
12
131. Connect your Android device via USB.
142. Run the following command in your terminal to forward the HTTPS port:
15 ```bash
16 adb reverse tcp:443 tcp:443
17 ```
18
19 > **Troubleshooting: "Permission denied"**
20 > If you see `adb: error: cannot bind listener: Permission denied`, your Android device restricts binding to ports below 1024 (like 443).
21 > **Solution:** Use a higher port on the device (e.g., 3000) and map it to 443 on your computer:
22 > 1. Run: `adb reverse tcp:3000 tcp:443`
23 > 2. Update `lib/services/api_client.dart`: `baseUrl = 'https://localhost:3000/api';`
24
25 *(If your server runs on a different port, e.g., 8080, run `adb reverse tcp:8080 tcp:8080`)*
26
273. Run the Flutter app:
28 ```bash
29 flutter run -d <device-id>
30 ```
31
32The app will now be able to connect to `https://localhost/api` just like your computer does.
33
34## Method 2: Android Emulator
35The Android Emulator uses a special IP address `10.0.2.2` to refer to the host computer's loopback interface.
36
371. Open `lib/services/api_client.dart`.
382. Change the `baseUrl` default value:
39 ```dart
40 // In lib/services/api_client.dart
41 this.baseUrl = 'https://10.0.2.2/api', // For Emulator
42 // this.baseUrl = 'https://localhost/api', // Default
43 ```
443. Run the app on the emulator.
45
46*Note: We have updated `DevHttpClient` to trust certificates from `10.0.2.2` automatically.*
47
48## Method 3: Wi-Fi Connection (Advanced)
49If you cannot use USB, you must use your computer's LAN IP address.
50
511. Find your computer's local IP address (e.g., `192.168.1.5`).
522. Open `lib/services/api_client.dart` and update `baseUrl`:
53 ```dart
54 this.baseUrl = 'https://192.168.1.5/api',
55 ```
563. **Important:** You must also update `lib/services/dev_http_client_io.dart` to trust this specific IP address in the `badCertificateCallback`:
57 ```dart
58 return host == 'localhost' || host == '127.0.0.1' || host == '192.168.1.5';
59 ```
604. Ensure your computer's firewall allows incoming connections on port 443 (or your server port).