How do I get my Android Emulator to talk to a local Rails-based API?

So I have an app built using Expo for both Android and iOS.

Now, this App needs to make fetch requests to a local API/gateway server that is based on Ruby on Rails, running using Foreman/Passenger.

The app is currently running inside an AVD (android emulator). I’m using macOS.

The AVD can access the local API/gateway using its built in Chrome browser. I can make simple GET requests to the root endpoint of the server, and use the Admin panel we’ve built in. This is all done insecurely though, because our Chrome isn’t trusting the Server’s certificate.

(We generated some SSL certificates that are CA signed, and Passenger is deploying these)

The Main Issue

Whenever we have our React Native app make requests to the local server (say, https://10.0.2.2:44300 in our case, since 10.0.2.2 is used to expose the Mac’s localhost to Android), the requests simply don’t go through. They time out.

I’ve been trying to figure out why this is happening, and I’m sure if it has anything to do with the certificate not being trusted by my device.

On iOS everything works fine, but we had to manually install the certificate that our server uses. Since Simulator recognizes localhost as the computer’s localhost, this isn’t an issue but the same certificate doesn’t work for Android.

What are some possible ways to troubleshoot this?

Thanks!

Hey @mobileapptech,

One suggestion would be to try and use http. As well, you could run ngrok if you can’t figure it out.

Cheers,

Adam

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.