react-native run-android ; SDK location no found, but it exists in the path

Viewed 5830

According to the react-native docs, I have installed Android 8.0 (Oreo) and the rest of the instructions. The only difference is that I have defined the path varibales in .bashrc and not .bash-profile. when I want to run my react-native application I face the Build failed with an exception.

the log looks like below:

sudo react-native run-android
Starting JS server...
Building and installing the app on the device (cd android && ./gradlew installDebug)...
Starting a Gradle Daemon, 1 incompatible and 1 stopped Daemons could not be reused, use --status for details

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.

the project built for me does not contain the local.properties. but I already have ANDROID_HOME in the Path.

$ printenv | grep Android
ANDROID_HOME=/home/amir/Android/Sdk
PATH=/home/amir/Android/Sdk/tools:/home/amir/Android/Sdk/tools/bin:/home/amir/Android/Sdk/platform-tools:/home/amir/Android/Sdk/emulator
1 Answers

As you mentioned local.properties not exist by default and you should add it to project.

  1. Go to your React native Project -> Android
  2. Create a file local.properties
  3. Open the file
  4. paste your Android SDK path like below

    in Windows sdk.dir =    C:\\Users\\USERNAME\\AppData\\Local\\Android\\sdk
    in macOS sdk.dir = /Users/USERNAME/Library/Android/sdk
    in linux sdk.dir = /home/USERNAME/Android/Sdk
    

Replace USERNAME with your user name

Now, Run the react-native run-android in your terminal.

Related