0

I have a react native app running on an android emulator and I'm trying to make a request to my local api(running on my laptop) at https://dev.mywebsite.com/api . This domain is host filed in the emulator like so :

/etc/hosts and /system/etc/hosts and /etc/system/hosts all have:

127.0.0.1       localhost
::1             ip6-localhost
10.0.2.2        dev.mywebsite.com

Note: I have also tried my local ip address of 192.168.1.13

The domain has a real ssl certificate and I'm able to access it from chrome on the emulator without issues.

Changing my api call to target https://mywebsite.com/api which is deployed in production does work.

Running adb shell and pinging dev.mywebsite.com shows 127.0.0.1 for some reason?

Why would chrome in the emulator work but my react native app doesn't? If you help me solve this I'll be so excited :) Maybe there's some workaround to this? I'll toss in a rep bounty.

EDIT

I got it working on a physical device(not emulator). I used an app called "Hosts Go" to host file to 192.168.1.13 and it works. Why does the Hosts Go app work but the emulator hosts file doesn't? I wasn't able to edit the hosts file on my physical device as it's not rooted to test that.

2 Answers 2

2

Well if this isn't on the trickier problems to debug...

Put a blank line at the end of your hosts file.

Chrome for some reason works if your hosts file doesn't have it, but a request from your app won't.

Sign up to request clarification or add additional context in comments.

Comments

2

when not blank line at the end of my phone hosts file, my meizu_16s_android10 phone hosts is still working

but when I run adb push 'C:/Windows/System32/drivers/etc/hosts' '/etc/hosts'

android hosts will be not working

I find windows use CRLF, android use LF

when i replace it, android hosts is working

1 Comment

Thank you, saving with a blank line at the end using LF fixed the issue for me as well!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.