[Solved] Unable to get Expo working - Android Emulator Networking Issue

❯ expo diagnostics

  Expo CLI 3.22.3 environment info:
    System:
      OS: Linux 5.4 Manjaro Linux
      Shell: 5.8 - /usr/bin/zsh
    Binaries:
      Node: 14.6.0 - ~/.nvm/versions/node/v14.6.0/bin/node
      Yarn: 1.22.4 - ~/.yarn/bin/yarn
      npm: 6.14.6 - ~/.nvm/versions/node/v14.6.0/bin/npm
    IDEs:
      Android Studio: 4.0 AI-193.6911.18.40.6626763
    npmPackages:
      expo: ~38.0.8 => 38.0.8 
      react: ~16.11.0 => 16.11.0 
      react-dom: ~16.11.0 => 16.11.0 
      react-native: https://github.com/expo/react-native/archive/sdk-38.0.2.tar.gz => 0.62.2 
      react-native-web: ~0.11.7 => 0.11.7 
    npmGlobalPackages:
      expo-cli: 3.22.3

Hi,

I successfully got React Native (aka eject mode) working without issue. It works fine with Android Emulators and my Android phone too. And now I was hoping to use Expo but, I’m having trouble getting it to work. No matter what I do, I can’t seem to get it to run on the emulator without it always giving me an error of some sort.

With a fresh copy of Node installed via nvm, I run npm install -g expo-cli. That’s fine. Then I login, also fine. Then I expo init my-app and chose blank template, which seems fine too. I cd into my-app and run yarn start. It brings up Metro in the browser, seems fine as well.

With a brand new emulator setup, I Run on Andorid device/emulator

I get the following error: Couldn't start project on Android: Error running adb: cmd: Can't find service: package and the popup says Error opening Simulator - I think it may be because the emulator wasn’t already running.

I run the emulator again and this time the popup is green and I get a success message but, I get the following error:

The View error log:

So I refresh…and I get the spinner for a bit. Then I get Building JavaScript bundle: finished in 18015ms. At which point I get the following error:

Reload does nothing so, I dismiss and I get this:

So I Run on Andorid device/emulator again and get the following two screens:


So I reload…

At which point I get the previous error:

And then the the whole thing starts over so, I turn off the Emulator and Metro and try to yarn start again but, that doesn’t help and it’s the stuck on “JavaScript 100%” screen again. So I close Expo and my-app on the emulator (square icon and swiping them up) but, I get the same Expo SDK error again.

I did see some posts on the Expo SDK error but, I haven’t been able to address it with any of the suggestions.

Any help would be greatly appreciated, thanks!

Update: seems to work fine on my physical device, just not the emulator.

Well, apparently you need internet connection on your emulator, who knew? :smiley:

In the package.json the sdk looks like this: "react-native": "https://github.com/expo/react-native/archive/sdk-38.0.2.tar.gz" and if there is no internet connection on the emulator it can’t find the sdk-38.0.8.tar.gz from the link.

To address this I followed the Emulator Networking:

When starting the emulator at the command line, you can also use the -dns-server <serverList> option to manually specify the addresses of DNS servers to use, where <serverList> is a comma-separated list of server names or IP addresses. You might find this option useful if you encounter DNS resolution problems in the emulated network (for example, an “Unknown Host error” message that appears when using the web browser).

To make it easy on myself I setup an alias in my .zshrc (.profile, .bash_profile etc.) like so:
alias phone="emulator @Pixel_3a_API_29 -dns-server 8.8.8.8" (Google’s dns.) That way I just type phone into the terminal and it starts up my emulator with a now working network (AndroidWifi) and everything is now working as expected.

The only issue with this setup is that you need to manually start the emulator instead of having Expo do it using either yarn android or expo start --android or yarn start and then clicking “Run on Android device/emulator” link in the left sidebar to start the emulator etc.

I’m going to see if I can address it on the host end (I’m on Manjaro - Linux) and if I can I’ll report back on how to do it (I’ve seen some tutorials on this for Windows; see link below.) That way I can just use Expo to launch the android emulator with networking already enabled; instead of manually starting with my alias from the terminal.

This might help others as well: https://stackoverflow.com/questions/42736038/android-emulator-not-able-to-access-the-internet (Note: some of the solutions are very similar to advice in many of the threads out there for the SDK error above but, none of those ever worked so, if you too have a networking issue, stick to the networking based solutions from this SO post that’s relevant to you and your machine.)

Happy to hear you got things figured out. Thanks for taking the time to share such a detailed answer with the community, @natetronn. We really appreciate when Expo users take time out of their day to help share information with the rest of us.

Cheers,
Adam

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