Wednesday, August 5, 2020

Android emulator not recognizing localhost

While configuring Google as an authentication provider for a react native app, I had to configure the redirect uri, which usually points to localhost.

However, the android emulator could not figure out the redirect uri, and that's because the android emulator and my PC are in different networks. localhost works on my PC, but the android emulator is its own network. The way to fix it is with adb reverse. Like this:

adb reverse tcp:44371 tcp:44371

The port number does not necessarily need to match, it can be different. The first port is the emulator's, and the second port is obviously your PC.