Unable to connect to device or emulator

First, I can build and run fine on both emulator and device (Pixel XL) just fine in Android Studio. I have come across several cases of this in other posts on git and stack overflow. None of the solutions have worked.

When I run expo start it opens the browser developer console for expo. When I click on “Run on Device/Emulator” . I get an error.

Starting Metro Bundler on port 19001.

WARNING 09:01 Couldn’t adb reverse: adb: error: unknown host service
ERROR 09:01 Couldn’t start project on Android: Error running adb: unknown host service

In command line “adb devices” lists my devices fine. When I run “adb usb” I get an error “error: unknown host service” . I assume this is the problem but I am having a hard time finding a solution.

I have tried completely uninstalling and reinstalling android studio and platform tools.

Expo CLI 3.4.1 environment info:
System:
OS: macOS 10.14.6
Shell: 5.3 - /bin/zsh
Binaries:
Node: 12.9.1 - ~/.nvm/versions/node/v12.9.1/bin/node
npm: 6.12.1 - ~/.nvm/versions/node/v12.9.1/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
IDEs:
Android Studio: 3.5 AI-191.8026.42.35.5977832
Xcode: /undefined - /usr/bin/xcodebuild
npmPackages:
expo: ^35.0.0 => 35.0.1
react: 16.8.3 => 16.8.3
react-native: https://github.com/expo/react-native/archive/sdk-35.0.0.tar.gz => 0.59.8
npmGlobalPackages:
expo-cli: 3.4.1

On a side note: The slack registration is broke. When I fill out email and click the Im not a robot button and click Get Invite I get an error in the button “not_allowed_token_type”. In dev tools it looks like its trying and failing to call a socket.io connection in both Chrome and Firefox.

What does adb devices give you?

(I believe the adb command that expo-cli is using is installed along with expo-cli. e.g. I have my node installation under /usr/local/node and adb is here:

/usr/local/node/lib/node_modules/expo-cli/node_modules/@expo/xdl/binaries/linux/adb/adb
/usr/local/node/lib/node_modules/expo-cli/node_modules/@expo/xdl/binaries/osx/adb/adb

If I run that adb devices with a phone connected I get something like this:

$ /usr/local/node/lib/node_modules/expo-cli/node_modules/@expo/xdl/binaries/linux/adb/adb devices
List of devices attached
999a9a999999999999	device

This is just a guess, but I think if the device ID contains colons it could potentially cause this error. (e.g. see this.) As to how you deal with that if that is the case, I don’t currently know :slight_smile: but maybe it gives you a place to start at least.

The adb devices command just gives me my currently connected device.

List of devices attached
HT68K0209999 device

When I look at “where adb” in commandline (mac) I see it located in the following directories.
/usr/local/bin/adb
/Users/myuser/Library/Android/sdk/platform-tools/adb

Do you think its possible that expo is using the wrong version of the command? If so would you know how to force it to use the right version?

Here’s the code:

Looks like it checks (using hasbin) if the binary is in the PATH. So in theory you should be able to remove /usr/local/bin and /Users/myuser/Library/Android/sdk/platform-tools from the PATH or else put the PATH to Expo’s version first in the PATH.

If that doesn’t help, maybe try running the adb commands manually to see which command fails:

packages/xdl/src/Android.ts:  let devices = await getAdbOutputAsync(['devices']);
packages/xdl/src/Android.ts:  let devices = await getAdbOutputAsync(['devices']);
packages/xdl/src/Android.ts:  let packages = await getAdbOutputAsync(['shell', 'pm', 'list', 'packages', '-f']);
packages/xdl/src/Android.ts:  let info = await getAdbOutputAsync(['shell', 'dumpsys', 'package', 'host.exp.exponent']);
packages/xdl/src/Android.ts:  let result = await getAdbOutputAsync(['install', path]);
packages/xdl/src/Android.ts:  return await getAdbOutputAsync(['uninstall', 'host.exp.exponent']);
packages/xdl/src/Android.ts:      await getAdbOutputAsync([
packages/xdl/src/Android.ts-        'shell',
packages/xdl/src/Android.ts-        'am',
packages/xdl/src/Android.ts-        'start',
packages/xdl/src/Android.ts-        '-a',
packages/xdl/src/Android.ts-        'android.intent.action.VIEW',
packages/xdl/src/Android.ts-        '-d',
packages/xdl/src/Android.ts-        _lastUrl,
packages/xdl/src/Android.ts-      ]);
packages/xdl/src/Android.ts:  let output = await getAdbOutputAsync([
packages/xdl/src/Android.ts-    'shell',
packages/xdl/src/Android.ts-    'am',
packages/xdl/src/Android.ts-    'start',
packages/xdl/src/Android.ts-    '-a',
packages/xdl/src/Android.ts-    'android.intent.action.VIEW',
packages/xdl/src/Android.ts-    '-d',
packages/xdl/src/Android.ts-    url,
packages/xdl/src/Android.ts-  ]);
packages/xdl/src/Android.ts:    await getAdbOutputAsync(['reverse', `tcp:${port}`, `tcp:${port}`]);
packages/xdl/src/Android.ts:    await getAdbOutputAsync(['reverse', '--remove', `tcp:${port}`]);

adb reverse commands result in error: unknown host service and I dont know why.

Actually they all result in the same error.

Did it make a difference which adb binary you used?

Unfortunately not.