React-native android debugger connecting to 10.0.2.2 instead of localhost

sKhan picture sKhan · Mar 26, 2018 · Viewed 11.7k times · Source

While running app with react-native run-android its connecting to 10.0.2.2:8081 instead of localhost:8081 and not able to debug.

Does anyone know how to fix so that it will connect to localhost instead?

Answer

Anshuman Jaiswal picture Anshuman Jaiswal · Jul 30, 2018

On MAC I solved it by doing following:

  1. Press Cmd + M on emulator screen
  2. Dev settings > Debug server host & port for device
  3. Set localhost:8081
  4. Rerun the android app: react-native run-android

Debugger is connected now!

Hope it will help others :)