'Trying to build react native app for Android on Mac M1 - Error: No emulators found as an output of `emulator -list-avds`

I have installed Android Studio on my mac M1
I have added a virtual device in Android Studio using Device Manager
The app builds fine from inside Android Studio......however when I run npx react-native run-android from command line in VSCode, I get the error No emulators found as an output of emulator -list-avds

However when I navigate to emulator folder using cd ~/Library/Android/sdk/emulator and run command ./emulator -avd {AVD_NAME}, the emulator starts fine.....however even with the emulator running, the command npx react-native run-android still gives the error No emulators found as an output of emulator -list-avds

UPDATE 04/26 - I followed instructions from @qqNade, however I am still getting same error...see screenshot below: enter image description here

Just noticed from the screenshot above, the error

/bin/sh: adb: command not found

..also, when I run echo $PATH in terminal, I get the following response:
/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin

I dont see any reference to android in there, so I assume thats not a good thing

UPDATE 04/26 #2
I added a ~/.zshrc file and populated it as per below:

export ANDROID_HOME="$HOME/Library/Android/sdk"
export 
PATH="$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$PATH"

..that solved the /bin/sh: adb: command not found error, but now I have a new one:

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: spawn ./gradlew EACCES
    at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:476:16)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)

....at least its launching the emulator now

UPDATE 04/26 #3
A number of SO posts told me to run the following command from android folder (and then clean)

chmod +x gradlew;

...now Im getting a different error:

Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
./gradlew: line 188: syntax error: unexpected end of file

Im wondering if this has anything to do with fact that I created the app originally on Windows.....and this is the first time Im trying to build on Mac?
I checked gradlew file in VSCode and its showing as LF (not CRLF) which as I understand it is correct when building for Mac



Solution 1:[1]

I also faced such a problem, to solve it you need to open a command prompt and enter

nano ~/.zsh_profile

after which you need to add this to the file and save

export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools

then enter on the command line

source $HOME/.zsh_profile

Solution 2:[2]

I want to help you.

You're in the home directory (you can go there with cd $HOME or cd ~)

export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools

source ~/.bash_profile (or source ~/.zshrc, take a look at my note at the end please)

After that, when you execute command vi .bash_profile (or vi .zshrc), you should see something like that

enter image description here

At this point, you can try to execute emulator -list-avds command again

And yes, echo $PATH should show you entries related with Android like ~/Library/Android/sdk/platform-tools

echo $ANDROID_HOME as well

If still not working, I would try to navigate to android folder and run the commands below one more time

chmod +x gradlew
./gradlew clean
react-native run-android

NOTE: Please be sure which shell your mac is using with the command below.

echo $0

Further reading

setting up development environment

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 qqNade
Solution 2