Run react-native on android emulator
Solution 1:
I had a similar problem, and after spending so much time and lots of searching about this issue the only trick worked for me:
- Please Install the Required SDKs as shown in this figure
Configure Required SDKs
- If You have already installed it, so you must have to update the following SDKs:
-
Android SDK Tool
(update it to latest version) -
Android SDK Platform-tools
(update it to latest version) -
Android SDK Build-tools
(update it to latest version) -
Android Support Repository
underExtra
folder (update it to latest version)
-
- You Must have at least Installed the Same version
Android API
as the installedAndroid SDK Build-tools
&Android SDK Platform-tools
version as shown in theConfigure Required SDKs
figure above.
Note: Local Maven repository for Support Libraries which is listed as the SDK requirement in the official docs of React-native is now named as Android Support Repository in the SDK Manager .
Solution 2:
On macOs I manage to fix this by adding:
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
to ~/.zsh_profile file.
and than type to your terminal
source $HOME/.zsh_profile
The issue was caused by using iTerm2 shell so it's required to edit its own config instead of default $HOME/.bash_profile as described in the official documentation https://reactnative.dev/docs/environment-setup
Solution 3:
React Native (On Mac OS Big SUR)
i was stuck here. But updating the environment settings for Android studio did the trick.
nano ~/.zshrc
and paste
export ANDROID_SDK_ROOT=$HOME/Library/Android/sdk
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator:$PATH
export PATH=$PATH:$ANDROID_HOME/tools:$PATH
export PATH=$PATH:$ANDROID_HOME/tools/bin:$PATH
export PATH=$PATH:$ANDROID_HOME/platform-tools:$PATH
export JAVA_HOME=$(/usr/libexec/java_home)
control + o
to save
then enter
then control + x
to exit
then do
source ~/.zshrc
to compile
kill the runnig terminals and run
npx react-native run-android
Solution 4:
I had similar issue running emulator from android studio everytime, or on a physical device. Instead, you can quickly run android emulator from command line,
android avd
Once the emulator is running, you can check with adb devices
if the emulator shows up.
Then you can simply use
react-native run-android
to run the app on the emulator.
Make sure you've platform tools installed to be able to use adb
. Or you can use
brew install android-platform-tools