Search code examples
androidproxyapn

My Android app cannot connect to localhost after setting APN


I have setup a local server running on 127.0.0.1/3000 on my MacBook. My Android app sends requests to 10.0.2.2/3000 to make connection with the server. This works pretty well until I configured the APN in the Android emulator settings. In the APN settings, I set the Proxy to be 192.168.x.xxx and the port number to be 8001. With these settings, the local server is not able to accept any messages sent from my app now. Closing the APN proxy is not an option because my app also needs to connect to some remote services. So how to connect to the local server with APN proxy on?


Solution

  • I find the answer. Instead of listening on 127.0.0.1/3000, I configured my local server to listen on 0.0.0.0/3000. Instead of making request to 10.0.2.2/3000 in my Android app, I now make request to 192.168.x.xxx/3000. The local server now can accept messages sent from my Android app.