android connect to PC's localhost when debugger on mobile device

前端 未结 5 929
梦谈多话
梦谈多话 2020-12-05 10:36

I want to debug my android application, I connect the android device to my PC using the USB cable. In my application there is a button to connect with localhost, ip for loca

5条回答
  •  执念已碎
    2020-12-05 11:11

    You can share your Mac's Internet connection over Wi-Fi. Then your Android app can connect to a Servlet running on the Mac with HTTP over Wi-Fi. The steps are:

    1. Run System Preference on Mac
    2. Goto "Sharing" tab
    3. Turn on "Internet Sharing"
    4. Select "Ethernet" in the "Share your connection from" combo
    5. Select "Wi-Fi" in the "To Computers Using" list box
    6. Use "Wi-Fi Options..." button to configure Wi-Fi security. Now your Mac is a Wi-Fi server, and it is sharing its Ethernet Internet connection.
    7. Configure your Android device's Wi-Fi to connect to your Mac (in Settings command)
    8. On your Mac, goto the Network tab in System Preferences, and select Wi-Fi in list to find out the IP address of your Mac on the Wi-Fi network (for me it was 169.254.66.223)
    9. In your Android App you can now connect to the Servlet in your Mac with "http://169.254.66.223:8080/YourServer/YourServlet"

提交回复
热议问题