Couldn't start project on Android: Cannot read property 'replace' of undefined

I can’t connect the Android emulator from Expo

2 Likes

Hi @javieribarra, sorry, but it’s to low information about de problem.

Try to edit your post and describe more your environment like:

  • SDK Version
  • Logs
  • A Piece of your code

The more, the better

I have the same problem, did you find a solution ?

Same here, recently I updated the Expo CLI version and starting showing this error. If I user the QR code the code runs fine.

I am also experiencing the same thing after upgrading my cli to the latest version. Are there any fix for this?

In my case there was another android device with developer mode “on” connected to my PC. It seems that it cannot handle this case correctly. After disconnecting the device from USB and restarting expo it all worked again.

hey there! can you elaborate on this? do you mean you had multiple android devices connected and it didn’t work in that case?

Yes. I plugged in one of my devices for charging and forgot about it. Then, when I tried to start expo on the emulator it was returning the exact same error the OP had: “Couldn’t start project on Android: Cannot read property ‘replace’ of undefined”.

I am aware that it cannot start if multiple “dev on” devices and emulators are connected at the same time. But I hoped it would help the OP find the reason why he could not connect to the emulator.

sorry just to clarify again because i’m not totally certain still - you had two devices plugged in to your computer, right? not including emulators

Here are the steps to reproduce:

  1. I had a device plugged in. In this case we are talking about my Galaxy Tab S2. It needs to be mentioned that the device has the developer mode active.
  2. I started up the expo with “expo start” on my PC
  3. Then I booted the android emulator.
  4. When I tried to press “a” in the terminal to start expo on the android emulator I got the error: “Couldn’t start project on Android: Cannot read property ‘replace’ of undefined” and the the app would not start.

To get it back working:

  1. unplug the device OR stop the emulator
  2. restart expo with “expo start”
  3. press “a” and it works as expected.

Not sure if this is relevant but I will add some more info:
this happened with Expo CLI 3.27.6 and expo 38.0.4

interesting, i have tried to reproduce this by using the same steps and pressing a gives me the following:

Opening on Android...
Opening exp://192.168.1.65:19000 on ONEPLUS_A6010

 Expo  Press ? to show a list of all available commands.

if you press shift+a what are the names of your device/emulator?

the reported error comes from this code: expo-cli/Android.ts at 6ad25c3dde3242bfdc2b0d8e846c7bb5fec14136 · expo/expo-cli · GitHub

this means that the result of adb devices -l is somehow not what is expected. can you try running that command manually when you are getting this error and let me know what the output is?

we can definitely handle this error but wrapping in try/catch and returning an empty array of devices… but it would be better to understand why adb devices -l is not working on your machine in some circumstances

1 Like

Hi Brent!
Shift+a does literally nothing.

adb devices -l gives the following:

List of devices attached
984e71340418728d       unauthorized transport_id:2
emulator-5554          device product:sdk_gphone_x86 model:Android_SDK_built_for_x86 device:generic_x86 transport_id:1

By looking at this line: unauthorized transport_id:2 I understood that the Tablet was missing some kind of authorization. So, I unplugged it, then plugged it back in and, of course it popped the message:

Allow USB debugging on this device? and the RSA fingerprint confirmation alert.

After I gave it permission for USB debugging, the adb devices -l message is now showing

List of devices attached
984e71340418728d       device product:gts28vewifixx model:SM_T713 device:gts28vewifi transport_id:3
emulator-5554          device product:sdk_gphone_x86 model:Android_SDK_built_for_x86 device:generic_x86 transport_id:1

Trying to start the expo app changed to:

Opening on Android...
Opening exp://192.168.1.148:19000 on SM_T713

So, the real issue was having a plugged in device with Developer mode set to On but without giving it authorization to actually work on it is what is stopping it from working correctly.

I think that the message should be updated to something more clear or, if the primary device is unauthorized, move on to the next device on the adb list.

I hope that helps.

Thanks for helping me debug this issue :slight_smile:

2 Likes

thanks for the info! given the output you shared i believe this is where the error is originating: expo-cli/Android.ts at 6ad25c3dde3242bfdc2b0d8e846c7bb5fec14136 · expo/expo-cli · GitHub - we should be able to fix this with this info.

re: shift+a doing nothing, that is weird given that the a key works, we actually just watch for a keypress of A which presumably shift+a does on your keyboard. which operating system and terminal app are you using? does ? show this prompt for you?

Screen Shot 2020-09-19 at 5.25.18 PM

shift+a should show this

Screen Shot 2020-09-19 at 5.25.37 PM

That seems to be the culprit, indeed. That should be an easy fix.

re: Shift+a doing nothing.

I am on a Win10 machine and I am using the PHPStorm integrated terminal and the PowerShell.

pressing ? works as expected.
However Shift+a seems to be scrolling the terminal at the end of the buffer on the PHPStorm terminal and clearing the buffer on PowerShell. So, not sure what’s the matter but it seems to be just system keybinding. So, no worries :slight_smile:

I just checked and it works as expected on my MacMini.

ah, hm, i wonder if that is a keybinding for windows or powershell within phpstorm

Not sure. I will not even pursue it further. It doesn’t really matter to me personally.

Thanks again for your assistance!

1 Like

@bacon fixed this in Support unauthorized devices by EvanBacon · Pull Request #2681 · expo/expo-cli · GitHub :slight_smile: i just released a new version of expo-cli with the fix included - expo-cli@3.27.8

2 Likes

I can confirm this is now working as expected with the above use case. Thanks for the fix!