Search code examples
androidgoogle-chromedebuggingmobileportforwarding

chrome inspect devices doesn't show ports


I am trying to debug an android app through localhost. I set the port forwarding and it was working as expected for some time. After a few sessions, I started getting network failure error. When I checked the devtools in chrome, it shows the device but its not showing the mapped port and the green status icon.

I tried reconnect the mobile, restart the mobile and my laptop and even tried with a different mobile. But it all results in same.

PS: I have tried some settings in Android studio to improve gradle build speed (work offline etc.) then reverted too.

Chrome devices


Solution

  • Port forwarding enables your Android device to access content that's being hosted on your development machine's web server. Port forwarding works by creating a listening TCP port on your Android device that maps to a TCP port on your development machine. Traffic between the ports travel through the USB connection between your Android device and development machine, so the connection doesn't depend on your network configuration.

    To enable port forwarding: 1.Set up remote debugging between your development machine and your Android device. When you're finished, you should see your Android device in the left-hand menu of the Inspect Devices dialog and a Connected status indicator. 2.In the Inspect Devices dialog in DevTools, enable Port forwarding. 3.Click Add rule. enter image description here 1. In the Device port textfield on the left, enter the localhost port number from which you want to be able to access the site on your Android device. For example, if you wanted to access the site from localhost:5000 you would enter 5000. 1. In the Local address textfield on the right, enter the IP address or hostname on which your site is running on your development machine's web server, followed by the port number. For example, if your site is running on localhost:7331 you would enter localhost:7331. 1. Click Add.

    Port forwarding is now set up. You can see a status indicator of the port forward on the device's tab within the Inspect Devices dialog.

    please view the link below for further explanation. https://developers.google.com/web/tools/chrome-devtools/remote-debugging/local-server