Timeout Error when connecting localhost api with Android Studio on Real devices through USB

后端 未结 3 786
我寻月下人不归
我寻月下人不归 2021-01-11 17:32

I am using Android Studio version 3 on Window 8.1. There is XAMPP installed to host php api on localhost. I am trying to access the localhost api from Android Studio.

<
3条回答
  •  离开以前
    2021-01-11 18:00

    Your access to local host via IPV4 works on emulator because your emulator and the host are on same network. It gives timeout on real device because, real device is not connected to same network as your host by just connecting through USB.

    There are two approaches:

    1. Ensure your device and host share the same network. It could be by connecting your device to host network through Wifi.

    2. If you cannot connect your device to the same network due to some constraints, then you can run following command:

      adb reverse tcp: tcp:

    Then use localhost instead of IPV4 in your URL

提交回复
热议问题