Cannot run `react-native run-android` (no error from react-native doctor)

1.5k views Asked by At

I followed official guide to setup React Native project on MacOS 14.1.1 (23B81) macbook air m2 (with a few differences that I will describe next).

Below is the result of npm run android. (npm run ios works perfectly)

info JS server already running.

info  Tip: Make sure that you have set up your development environment correctly, by running react-native doctor. 
To read more about doctor command visit: https://github.com/react-native-community/cli/blob/main/packages/cli-doctor/README.md#doctor 

So, I run npx react-native@lastest doctor but got no error or warning.

Common
 ✓ Node.js - Required to execute JavaScript code
 ✓ yarn - Required to install NPM dependencies
 ✓ Watchman - Used for watching changes in the filesystem when in development mode

Android
 ✓ Adb - Required to verify if the android device is attached correctly
 ✓ JDK - Required to compile Java code
 ✓ Android Studio - Required for building and installing your app on Android
 ✓ Android SDK - Required for building and installing your app on Android
 ✓ ANDROID_HOME - Environment variable that points to your Android SDK installation

iOS
 ✓ Xcode - Required for building and installing your app on iOS
 ✓ Ruby - Required for installing iOS dependencies
 ✓ CocoaPods - Required for installing iOS dependencies
 ✓ ios-deploy - Required for installing your app on a physical device with the CLI
 ✓ .xcode.env - File to customize Xcode environment

Errors:   0
Warnings: 0

I have no idea what should I fix...


My setup steps that differ from the official guide are

  1. I have installed brew install --cask zulu11, but I got an error that react-native doctor could not found AndroidSDK. I tried to fix this problem with several solutions from Google , but the problem still persist.
    1. Download cmdline-tools (Android Studio > SDK Manager > SDK Tools)
    2. Create local.properties with data sdk.dir=/Users/<user>/Library/Android/sdk <ref.this answer>
  2. I downloaded and installed JDK17. Then, update $JAVA_HOME in .zshrc. Run java --version and echo $JAVA_HOME to make sure that java version was successfully updated. Run npx react-native@lastest doctor and found that no issue found.
1

There are 1 answers

0
Martinocom On

I don't know if it can help, but here are some tips:

  • If you're using Java only for this project (or for RN generally), remove any other java version from your machine (like the Java 17 you've mention before).

  • Use the suggested java version (zulu-11) and use only that for RN. Set all the env variables for it as said in the guide.

  • Are you sure that you executed the downloaded file from zulu-11 to finish the setup? My first time I just forgot to launch it and I was wondering why Java was not installed.

  • if you open your bash and type adb devices with a simulator or device attached, is there any output? If not, you have some problems with Android Setup

  • I suppose you created a RN probject (non-expo): can you open your ./Android folder with Android Studio and try to sync gradle, clean and rebuild the whole project?

  • JS Server Already running is only telling you that Metro is running. You can stop all the bash(es) and try to launch npm/yarn start --reset-cache to have a nice clean metro server up and running.

  • You can delete node_modules, the .lock files and the build and outputs folders for Android and try to resync everything.

  • Try to execute commands to see if they're correctly setup: npm -v, yarn -v, nvm -v, node -v, java --version etc...