49

I've followed the installation instructions for ReactNative on the official site but can't get my project to build and install on any device. The issue seems to be that ReactNative can't seem to locate my Android SDK.

If I open the Android specific part of the project in Android Studio I can start the app, so the SDK is properly installed. Maybe related is also that I'm working on a Flutter app simultaneously and Flutter has no problems locating the Android SDK.

Running nix react-native doctor gives me the following:

Common
 ✓ Node.js
 ✓ yarn
 ✓ Watchman - Used for watching changes in the filesystem when in development mode

Android
 ✓ JDK
 ✓ Android Studio - Required for building and installing your app on Android
 ✖ Android SDK - Required for building and installing your app on Android
   - Versions found: N/A
   - Version supported: 29.0.2
 ✓ ANDROID_HOME

iOS
 ✓ Xcode - Required for building and installing your app on iOS
 ✓ CocoaPods - Required for installing iOS dependencies
 ✓ ios-deploy - Required for installing your app on a physical device with the CLI

Errors:   1
Warnings: 0

Attempting to fix 1 issue...

Android
 ✖ Android SDK
   Read more about how to download Android SDK at https://reactnative.dev/docs/getting-started

However trying to "fix" the issue just takes me to the getting started page, and as I mentioned before I've done the installation exactly as described. I even tried removing everything related to Android from my computer and reinstalling everything from scratch.

Runnit nix react-native info gives me the following:

info Fetching system and libraries information...
System:
    OS: macOS 10.15.4
    CPU: (8) x64 Intel(R) Core(TM) i7-3720QM CPU @ 2.60GHz
    Memory: 1.97 GB / 16.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 12.16.3 - /usr/local/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.14.4 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.9.3 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 13.5, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
    Android SDK: Not Found
  IDEs:
    Android Studio: 4.0 AI-193.6911.18.40.6514223
    Xcode: 11.5/11E608c - /usr/bin/xcodebuild
  Languages:
    Java: 14.0.1 - /usr/bin/javac
    Python: 2.7.16 - /usr/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.11.0 => 16.11.0
    react-native: 0.62.2 => 0.62.2
  npmGlobalPackages:
    *react-native*: Not Found

Which just further "proves" that ReactNative can't find the Android SDK.

What I've tried so far:

Adding a local.properties with the content:

sdk.dir=/Users/[username]/Library/Android/sdk

(And yes the folder exists and is correct, it's the same one set in Android Studio)

Updating the .zshrc with:

export ANDROID_HOME=$HOME/Library/Android/sdk
export ANDROID_SDK_ROOT=$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

And in that sdk-folder (in platforms) I have android-28, android-29 and android-30. I've also (of course) looked at a number of posts here from people with the same issue, but one of these two fixes almost always seems to solve the issue, however it doesn't work for me. What else is there to test?

UPDATE: I can also add that when running npx react-native run-android and tget the error: Task 'installDebug' not found in project ':app'.. But this problem should also be solved with the properties.local, which doesn't work for me.

2
  • have you got the solution? Commented Jan 4, 2021 at 6:52
  • Hi @Sebastian, did you found any salutation, I am having the same error, please help. Commented Mar 18, 2021 at 13:37

14 Answers 14

49

I figured out that installing the "Android SDK Command-line Tools" plugin in Android Studio will allow doctor to recognize a newer android sdk instance!

But it's incompatible with react-native, we need the 29.0.2 one so be sure to check "Show package details" and select the correct version before downloading it.

Android Studio settings

My npx react-native doctor output after that:

michel@michel-ubuntu:~/development/projects/Project$ rn doctor
Common
 ✓ Node.js
 ✓ npm

Android
 ✓ JDK
 ✓ Android Studio - Required for building and installing your app on Android
 ✓ Android SDK - Required for building and installing your app on Android
 ✓ ANDROID_HOME

Errors:   0
Warnings: 0
Common
 ✓ Node.js
 ✓ npm

Android
 ✓ JDK
 ✓ Android Studio - Required for building and installing your app on Android
 ✓ Android SDK - Required for building and installing your app on Android
 ✓ ANDROID_HOME

Errors:   0
Warnings: 0
Sign up to request clarification or add additional context in comments.

Comments

30

What worked for me, despite trying most solutions above and following the Setting up the development environment guide from the React Native site, was to make sure that the Android SDK Command-line Tools (latest) was installed in the Android Studio Settings. After running npx react-native doctor, Android SDK found was now configured. See steps below:

LAUNCH ANDROID STUDIO: (Your version may look similar) enter image description here

SELECT THE "SDK TOOLS" TAB (this may vary for you.) enter image description here

1 Comment

This definitely was the piece I was missing on my machine. However, in addition to this step, I also had to add/revise my path to point at the new Android/Sdk/cmdline-tools/latest/bin directory as the old tools path didn't include the new Latest step
10

Steps to fix this on (mac m1):

  • Follow Steps from https://reactnative.dev/docs/environment-setup

  • ensure you have added JAVA_HOME in ~/.zshrc

    export JAVA_HOME=/Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home
    
  • As described in environment-setup you need to install Android 13 (Tiramisu) only.

  • make sure the following items are checked:

    • Android SDK Platform 33
    • (for Apple M1 Silicon) Google APIs ARM 64 v8a System Image
  • Then configure Env Vars:

    export ANDROID_HOME=$HOME/Library/Android/sdk
    export PATH=$PATH:$ANDROID_HOME/emulator
    export PATH=$PATH:$ANDROID_HOME/platform-tools
    
  • Make sure you install SDK Build tools version 33 by checking show packages checkbox and

  • SDK Command line tools version 33.

    export PATH=$PATH:$ANDROID_HOME/cmdline-tools/10.0/bin
    

1 Comment

export PATH=$PATH:$ANDROID_HOME/cmdline-tools/10.0/bin this worked for me, thank you
7

KEY POINTS: Shall the command "sdkmanager" run correctly, will the command "react-native doctor" run correctly.

So we should firstly make "sdkmanager" run correctly in the command line.

Firstly, remove $ANDROID_HOME/tools, $ANDROID_HOME/tools/bin from the PATH. The sdkmanager in these folders is old, and requires oracle jdk 8. While in contrast the react native requires jdk >= 11.

Secondly, add $ANDROID_HOME/cmdline-tools/10.0/bin to the PATH.(You can replace 10.0 with your own version)

export ANDROID_HOME=$HOME/Library/Android/sdk
export ANDROID_SDK_ROOT=$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 PATH=$PATH:$ANDROID_HOME/cmdline-tools/10.0/bin

Then the command "sdkmanager" will run correctly. And the command "react-native doctor" will run correctly too.

Inspired by this answer: https://stackoverflow.com/a/68382384/7994724

3 Comments

Thanks for this! Regarding replace 10.0, I only had "latest", I guess that will be more future proof (or not)
in my case, sdkmaganer is working but npx react-native doctor is not!
In order to work with older versions of JAVA_HOME, like the Zulu11 version recommended for react-native 0.72 and earlier, you must install v 10.0 of the command line tools and add the path to that version as described in this answer. If you are using Zulu17, then you can download the latest command line tools and use the path to that: .../cmdline-tools/latest/bin
6

Open Android Studio;

More Actions > SDK Manager;

SDK Tools tab;

Select Android SDK Command-line Tools (latest);

Hit Apply and let it install the package;

Try re-running the npx react-native doctor command to see if this fixes your problem

1 Comment

this worked with me
3

Also, check JVM version referenced by JAVA_HOME. Reason: npx react-native doctor uses envinfo to gather available SDKs, which in turn calls ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --list, which can throw exceptions if too old JVM is used.

In my case, switching to Java 17 helped.

3 Comments

You nailed here! I followed the official documentation to install Java Azul Zulu and it doesn't run the sdkmanager properly. After switching to Java 19, it started finding the SDK
Installing cmdline-tools/latest did the trick for me !
Removed java 11 and installing java 17 worked for me
3

I tried all the answers in stackoverflow and github issues. But the below trick worked for me. In my case I configured the PATH variable in this way so that react-native doctor finds the correct tools.

export PATH=$ANDROID_HOME/emulator:$PATH
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/platforms:$PATH
export PATH=$ANDROID_HOME/tools/bin:$PATH
export PATH=$ANDROID_HOME/cmdline-tools/latest/bin:$PATH

Comments

2

Open ur android folder with Android Studio, Android Studio will try to install the required SDK for you.

Comments

2

Even though you have followed all the mentioned steps in the documentation, installed SDK tools and SDK platforms, if you are not able to run the Android app, the only issue is you don't have permission to run ./gradlew

So, in order to provide permission; run

cd android
chmod +x gradlew

./gradlew clean

This will provide the execution permissions.

Then you can build your Android application using

npm run android

Thanks :)

Comments

1

Install android command line tools from android studio SDK manager (SDK tools tab). then add <YOUR_ANDROID_SDK_PATH>\cmdline-tools\latest\bin to PATH environment variables

Comments

0

In my case, I resolved this erros when set version Java of the gradle to use jdk11 and not use android studio version jdk.

1 Comment

Me too: Error: LinkageError occurred while loading main class com.android.sdklib.tool.sdkmanager.SdkManagerCli java.lang.UnsupportedClassVersionError: com/android/sdklib/tool/sdkmanager/SdkManagerCli has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0
0

Replacing JDK to version 19 works for me.

enter image description here

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
0

Simply installing the latest version of SDK Command line tools on android studio worked.

1 Comment

there is a link which looks suspicious, please remove it
-1

this steps worked for me.

  1. open your system environment variable>advance>enveronment variables.
  2. delete every all paths related to sdk. including android_home and android_home_root. now restart your system. go back to the environment variable and click on path>edit. in the window that popup select new and add the path to your sdk. (for me "C:\Users\AppData\Local\Android\Sdk", yours might be diffrient). add path to platform-tools in same maner and comandline-tools. click ok to save and hopefully it will work.

1 Comment

English is not good. It lacks punctuation and there are some important typos. Please mark literals with "" (double quotes).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.