Error while building Android?

I see you are on macOS. Add the following to your .bash_profile:

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
export ANDROID_SDK_ROOT=$ANDROID_HOME
export ANDROID_AVD_HOME=$HOME/.android/avd
alias emulator='$ANDROID_SDK_ROOT/tools/emulator'

This should fix the error above. Laurent also added npx jetify to the build process to get around some issues that started with the transition to Android 10, so you shouldn't run into any other weird errors.
Please note that you have to start the emulator manually. For some reason it is not started automatically as it is done with run-ios.

But to be honest, I also have a few issues with the Android build environment. I have found a workaround, which is really irritating, but it's the only way to get it to run properly.

So, should you run into the same problem I had later on, have a look at:

The fix is truly annoying, since it has to be run every time before running react-native run-android, but it was the only way for me to get it to work (never had any issues with run-ios):

react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

I hope the info helps. If not, I'll be back after I had a decent sleep.

1 Like