Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReactNative can't locate Android SDK

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.

like image 408
Sebastian Avatar asked Jul 08 '20 14:07

Sebastian


People also ask

How do I fix Android SDK not found?

Quick fix: Go to the Tools –> SDK manager –> SDK tools. Deselect Hide obsolete packages option on the right bottom and further install Android SDK Tools(obsolete). A new folder named Tools is now generated in the SDK directory. (C:\Users\..

Can not find Android SDK folder?

If you have downloaded the AS + SDK bundle: Note #2: you will never find the SDK in the Android Studio directory unless you have explicitly put it in there. The reason is that those directories might be deleted after installing a newer version of Android Studio and you would have to re-install the SDK as well.

How do I fix sdk location not found?

Close the current project and you'll see a pop-up with a dialog which will then proceed to Configure option. Configure -> Project Defaults -> Project Structure -> SDKs on left column -> Android SDK Home Path -> give the exact path as you did on local. properties and select Valid Target.

Where is my Android SDK location?

by default, the "Android Studio IDE" will be installed in " C:\Program Files\Android\Android Studio ", and the "Android SDK" in " c:\Users\username\AppData\Local\Android\Sdk ".


1 Answers

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
like image 67
Michel Calheiros Avatar answered Nov 15 '22 00:11

Michel Calheiros