582

I have error when i start running android

What went wrong:
A problem occurred evaluating project ':app'.  
> SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Pyae Sone Nyein
  • 5,821
  • 3
  • 10
  • 3
  • this was happening with me in the first ever hello world, even the env variable was set correctly, what I did is, open the android folder in android studio and hit the run button(green play icon) and it worked, make sure your metro is running while you are doing this, i think it was happening because i didnt opened the android studio after installation when I opened the android folder in andriod studio I noticed it updated few things and now even npm run android is working fine – Inzamam Malik Mar 12 '21 at 19:10

35 Answers35

1000
  • Go to the android/ directory of your react-native project
  • Create a file called local.properties with this line:
sdk.dir = /Users/USERNAME/Library/Android/sdk

Where USERNAME is your macOS username

Ronan Boiteau
  • 9,608
  • 6
  • 34
  • 56
Ravin
  • 10,278
  • 1
  • 14
  • 20
  • * What went wrong: A problem occurred configuring project ':app'. > The SDK directory '/usr/local/android-sdk ' does not exist. But actually my sdk is exist in this path – Pyae Sone Nyein Sep 18 '15 at 07:31
  • 4
    Did you guys fix this issue? I'm also facing this right now. – Gasper Oct 12 '15 at 12:23
  • 14
    I was able to fix this by running from Android Studio. Once you've done that it works from the command-line. – Gant Laborde Feb 01 '16 at 16:39
  • Yeah creating that local.properties did solve my issue. Strange but works. – Sanj Feb 16 '16 at 01:40
  • 147
    If your on windows `sdk.dir = C:\\Users\\USERNAME\\AppData\\Local\\Android\\sdk` – Razze Aug 31 '16 at 23:05
  • This works! Not sure why this answer is not in the top of the answers! – Nagarajan Shanmuganathan Jan 04 '17 at 12:13
  • 1
    also make sure you have the android SDK installed https://developer.android.com/studio/index.html, if that's not obvious :) – Cole Jan 23 '17 at 02:56
  • `C:\Users\kalam\AppData\Local\Android\Sdk` it work for me – MD Ashik Apr 21 '17 at 21:11
  • Hi, I'm new. May I know create what kind of file and name it `local.properties` ? `txt` or other format ? – FeelRightz Aug 13 '17 at 14:58
  • this has fixed issue for me and I am able to issue react-native run-android which will install app on both emulator and real device when one is connected. Thank you so much! – pixel Aug 29 '17 at 05:39
  • Is there a way not to do this every time ? – rsanath Dec 24 '17 at 10:48
  • Check if your local.properties file format is not .txt or .rtf. It is .properties. – felixwcf Mar 02 '18 at 04:00
  • is there any way the local properties folder gets added by default , when starting a new react project , like in android studio it gets added automatically . – JSONParser Apr 12 '18 at 06:10
  • A note to people who're editing this to exclude `/Users/USERNAME`: `sdk.dir` expects to be started with `/`, it doesn't take `~` as home directory – mehulmpt Jun 26 '18 at 17:10
  • You should set the ANDROID_PATH instead of setting it in local.properties. Doing so will make it a permanent solution across all your projects, and will not cause problems to other dev in the team should the local.properties file get placed in a code revision tool. – Francois Nadeau Aug 30 '18 at 16:13
  • Very late, very inexperience but: sdk.dir=$HOME/Library/Android/sdk – Nilesh Sep 19 '18 at 15:43
  • This solved the error. Inside the project folder, I created the new file local.properties and added the line you mentioned with my Mac username. – itzo Oct 09 '18 at 08:16
  • This error would specially appear if you have copied the project or downloaded the zip file . It woun't appear if it's a new project or it's been cloned from git – Pratik Khadka Feb 03 '19 at 11:01
  • This only works per-project basis. Editing the system variables would be a better long-term solution if you're working with multiple projects. – Hylle Mar 23 '20 at 18:57
  • for windows create file local.properties and paste 'sdk.dir = C:\\Users\\ [your User Name]\\AppData\\Local\\Android\\Sdk' – Tushar Kshirsagar Oct 15 '20 at 16:31
  • Future note: instead of this you will want to add enviromental variable to `eas.json` for the EAS builds – jave.web Mar 23 '22 at 18:07
  • 1
    Doesn't work for me. – Karolis May 16 '23 at 09:31
483
  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.

Naveen T P
  • 6,955
  • 2
  • 22
  • 29
130

You can try adding ANDROID_PATH

export ANDROID_HOME=/Users/<username>/Library/Android/sdk/
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
Nish
  • 1,656
  • 1
  • 10
  • 19
  • 13
    I already have `ANDROID_PATH` in environment (Ubuntu, .bashrc file). However, for some reasons I am still geting the issue. I fixed it by creating `local.properties` and putting the path as stated in other answers. – Hesam Aug 01 '17 at 20:40
  • 3
    I have a mac and env var ANDROID_HOME did not help. `local.properties` did, however. – Henrik Jan 06 '19 at 14:06
  • For me, I use direnv, so I added basically the same thing to `.env` and now `react-native run-android` at least launches the emulator. i have `ANDROID_HOME=$HOME/Library/Android/sdk/; PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools` but on two lines. – jerryb Mar 16 '21 at 10:19
81

Open ~/.bash_profile and add:

 export ANDROID_HOME=~/Library/Android/sdk/
 export PATH=$PATH:~/android-sdks/platform-tools/
 export PATH=$PATH:~/android-sdks/tools/

source ~/.bash_profile

enter image description here

Void Asif
  • 147
  • 7
notdrone
  • 1,793
  • 15
  • 12
  • 11
    Works. Remember to restart Terminal, or type `source ~/.bash_profile` to make new export lines take in effect. – Raptor Aug 16 '17 at 03:39
  • Can you please add if any body is unable to find the bash_profile then create one as for the first timers they are unable to find that (So do I :p) – snehal agrawal Jul 21 '19 at 19:51
70

I don't think it's recommended to update the local.properties file to get to add the missing environment vars.

Update your environment variables:

How to open the AVD manager on OSX from iTerm2?

android-28 / android-30

sdk can be installed on /Library/Android/sdk or /usr/local/ to be sure check it by

which sdkmanager

Export ANDROID_HOME

export ANDROID_HOME=$HOME/Library/Android/sdk

or

export ANDROID_HOME="/usr/local/share/android-sdk"

Then add it to the $PATH

export PATH=$ANDROID_HOME/tools:$PATH
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/build-tools/28.0.1:$PATH

android-23

export ANT_HOME=/usr/local/opt/ant
export MAVEN_HOME=/usr/local/opt/maven
export GRADLE_HOME=/usr/local/opt/gradle
export ANDROID_HOME=/usr/local/share/android-sdk
export ANDROID_SDK_ROOT=/usr/local/share/android-sdk
export ANDROID_NDK_HOME=/usr/local/share/android-ndk
export INTEL_HAXM_HOME=/usr/local/Caskroom/intel-haxm

I used brew cask to install Android SDK following these instructions.

More info see https://developer.android.com/studio/intro/update#sdk-manager

locropulenton
  • 4,743
  • 3
  • 32
  • 57
38

echo "sdk.dir = /Users/$(whoami)/Library/Android/sdk" > android/local.properties

snowcamel
  • 671
  • 6
  • 10
  • 1
    This is the safest way as you are not changing any global system files. And for those that dont have that type of admin access to their machine. – GravyPlaya Dec 16 '16 at 23:58
29

Updated steps for React Native0.58 to get started on MAC/Unix

  • Open bash_profile in terminal

nano ~/.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

Control+S to save
Control+X to exit
Y to save changes
  • Update changes in terminal

source ~/.bash_profile

  • Validate Path:

echo $PATH

  • Confirm if all okay:

adb devices

Community
  • 1
  • 1
Hitesh Sahu
  • 41,955
  • 17
  • 205
  • 154
28

If you are on windows escape (add backlashes to) the backslashes and the colon in the android/local.properties file. If its not there then create it

sdk.dir = C\:\\Android\\sdk
Sajjad Ashraf
  • 3,754
  • 1
  • 34
  • 35
28

For Windows Users

One simple solution is to set the SDK path to the Enviroment Variables list.

  1. Head over to the Enviromnent variables. (Your PC > Properties )
  2. Create New System variables
  3. Set the Variable name to ANDROID_HOME
  4. Set the Variable value to your Android Sdk Location
  5. Press OK (3 times for 3 dialog boxes)

Note:

Your Android Sdk is generally located in

C:\Users\YourUserName\AppData\Local\Android\Sdk

Make sure to close your current terminal because your terminal holds all of your pre-existing Environment Variables.

Ozesh
  • 6,536
  • 1
  • 25
  • 23
16

Fixing SDK Path Errors on Linux Distributions


Your project is not finding the SDK set in the Project Settings via the path provided, so the project needs to be pointing in the right direction, and you have a couple options to accomplish this, but let's start by finding the correct SDK folder first.


Finding your SDK


From Package Manager


If you are using a package-based JRE install like Java 8 JRE via a the custom PPA in a Debian-based distribution, or used OpenJDK, the directory will most likely be /usr/lib/jvm/java-8-oracle (or whatever version you have chosen). You can find this path set in the JAVA_HOME environment variable:

$ echo $JAVA_HOME
 /usr/lib/jvm/java-8-oracle

Manual Download


If you have installed via the Java JRE/SDK download, it will be wherever you placed the folder, e.g. /home/username/jdk-8u121_1.8.0 (or something similar).

Scripted installs may even add the SDK to /opt/java-8-oracle, but as of this writing, the Java Install instructions leave the folder placement in your hands.


Android Studio 2.2


Lastly if you are using Android Studio, the SDK is placed where you have set it to place the SDK files downloaded through the Studio's SDK Manager. By going to File > Settings > Appearance & Behavior > System Settings > Android SDK, you can find the SDK location setting at the top with the option to change, and the default folder being ~/Android/Sdk.

Android Studio SDK Path

Setting the SDK Path

Now that we know where the SDK is, it is time to let react-native know.


Option 1: Set with local.properties


This method is very simple, and all that is needed is creating the file local.properties in the following folder, where Project_Folder is the base of your React-Native application:

Project_Folder/Android/App

In your local.properties, you want to set the variable sdk.dir to the path of your SDK folder:

sdk.dir=/home/username/Android/Sdk

While this is the easiest way to remedy the issue, it is not the best, especially if you work with multiple projects. For every project, you will have to create this file for every project, and if the folder changes plan on changing this file for each project's local.properties.

Once the file is saved, rerun the react-native run-android command.


Option 2: Settings Folders with Environment Variables


The other option is to set the SDK folders to the local environment variables that React-Native looks for by default. To do so, we will add the ANDROID_HOME path. As a bonus we can also add our android tools in the same place. We need to add this to rather the .bash_profile or .profile files in our home directory, which are loaded last, so we can make sure that nothing else is overriding the settings we make. Since these are in your home directory, there is no need to edit with escalated privileges.

**$ vim ~/.profile**  (use nano or pico if you prefer)

In the file add the following lines replacing the SDK folder with the one you found above. I will be using the Android Studio folder as an example:

export ANDROID_HOME="~/Android/Sdk"
export PATH=$PATH:~/Android/Sdk/tools:~/Android/Sdk/platform-tools

Save the file, then apply the profile settings:

$ source ~/.profile
$ echo $ANDROID_HOME
/home/dbrown/Android/Sdk

If the Sdk folder shows correctly, congratulations! Re-run your react-native command, and watch the app build process continue forward.


If you still have issues


If for some reason you receive the error "> failed to find target with hash string 'android-23' in: your/sdk/folder, you need to make sure that the project's build version and the version of the SDK installed match (React-Native defaults to 23.0.1). You can find the default version in Project_Folder/android/app/build.gradle, and then searching for buildToolsVersion. You can of course change the version from this file, or in Android Studio go to File > Project Structure to change the Project SDK. I would not suggest changing this version unless you absolutely know what you are doing, otherwise install the SDK version the project is looking for.

DBrown
  • 5,111
  • 2
  • 23
  • 24
12

This answer is for MacOs Catalina user or zsh users as your Mac now uses zsh as the default login shell and interactive shell.

If you follow along with the docs of React Native Setting up the development environment guide. Then do the following.

Firstly check if local.properties file exists or not. If the file does not exist then create and add the following line.

sdk.dir=/Users/<youcomputername>/Library/Android/sdk

After doing the above changes now do the following.

  1. Open ~/.zshrc using a code-editor. In my case I use vim
vim ~/.zshrc
  1. Add the following line for the path.
export ANDROID_HOME="/Users/<yourcomputername>/Library/Android/sdk"
export PATH=$ANDROID_HOME/emulator:$PATH
export PATH=$ANDROID_HOME/tools:$PATH
export PATH=$ANDROID_HOME/tools/bin:$PATH
export PATH=$ANDROID_HOME/platform-tools:$PATH

Make sure to add the above line correctly else it will give you a weird error.

  1. Save the changes and close the editor.

  2. Finally, now compile your changes

source ~/.zshrc

I get this working in my case. I hope this helps you.

Pratap Sharma
  • 2,633
  • 2
  • 18
  • 32
11

You must write correct full path. Don't use '~/Library/Android/sdk'

vi ~/.bashrc

export ANDROID_HOME=/Users/{UserName}/Library/Android/sdk
export PATH=${PATH}:${ANDROID_HOME}/tools
export PATH=${PATH}:${ANDROID_HOME}/platform-tools

source ~/.bashrc
hoi
  • 2,168
  • 20
  • 22
7

On Ubuntu, where you have to get SDK separately from the Android Studio strange the path will work with Android Studio but with React Native, you'll need to create a file name local.properties.

For example inn ~/AwesomeProject/android and insert this line:
sdk.dir=/path/to/sdk/in/your/computer

xlm
  • 6,854
  • 14
  • 53
  • 55
connelblaze
  • 779
  • 1
  • 10
  • 19
7

Delete the local.properties from the android folder in your react project and try it.

I've done this and succeeded.

Zaid Qureshi
  • 611
  • 10
  • 19
6

Check out in your local.properties file:

sdk.dir=C\:\\Users\\USERNAME\\AppData\\Local\\Android\\sdk

if the format is proper or not

currarpickt
  • 2,290
  • 4
  • 24
  • 39
Makvin
  • 3,475
  • 27
  • 26
5

If you are using Ubuntu, just go to android directory of your react-native project and create a file called local.properties and add android sdk path to it as follow:

sdk.dir = /home/[YOUR_USERNAME]/Android/Sdk
Keivan
  • 1,300
  • 1
  • 16
  • 29
4

Copy your system's other android project local.properties and paste in android folder of React-native project it will work.

Rathore
  • 1,926
  • 3
  • 19
  • 29
4

This worked for me .

I am taking Stephen Grider's React Native on Udemy and one of the students posted this in Lecture 50. Pasted verbatim in the command line (w/o '$' of course).

$ export "ANDROID_HOME=/usr/local/opt/android-sdk" >~/.bash_profile
xlm
  • 6,854
  • 14
  • 53
  • 55
Utah
  • 49
  • 1
  • Dont do this. it will result in the error `> The SDK directory '/usr/local/opt/android-sdk' does not exist.` – thexande Apr 07 '17 at 23:11
3

The best solution I can find is as follows:

  1. Download Android Studio and SDK of your choice (Even if you think you don't need it trust me that you would need it to release the apk file and some manual changes to the android code).
  2. File > New > Import , point to the location where your react native android project is.
  3. If it ask you to download any specific SDK then please download the same. It can ask you to update gradle etc... Please keep on updating where required.
  4. If you have an existing Android SDK and you know the version then all you have to do is match that version under build.gradle of your android project.

This is how the gradle file will look like:

enter image description here

If everything has gone well with your machine setup and you can compile the project using the Android Studio then nothing will stop you to build your app through react-native cli build android command.

With this approach, not only you will solve the problem of SDK, you will also resolve many issues related with your machine setup for Android development. The import will automatically find SDK location and create local.properties. Hence you don't need to worry about manual interventions.

codebased
  • 6,945
  • 9
  • 50
  • 84
2

For Linux Users

Your app is not getting the path of android-sdk, so If you are using linux (ubuntu), than you need to add a file named "local.properties" and save it inside the android folder, which is created inside your app folder.

You need to add below line inside local.properties file, which is the path of your android-sdk lies inside your system inside system in order to run the app.

sdk.dir=/opt/android-sdk/

save and rerun the command react-native run-android

OR

you can open terminal, type

sudo nano ~/.bashrc

and paste the below path at the end of the file

export ANDROID_HOME="/opt/android-sdk/"

and restart your computer and run again react-native run-android after that.

Note:- If you put set path in .bashrc file, then you don't even need to create local.properties file.

Yash Vekaria
  • 2,285
  • 24
  • 24
  • This shouldn't be an hardcoded solution but depends on where Android Studio SDK is been installed. In my case is sdk.dir="pathWhereAndroidSDKisbeeninstalled/Android/Sdk" – Carmine Tambascia Aug 05 '19 at 21:39
  • Actually on my side the SDK were installed initially in /root/. I had to move the /root/Android/Sdk to /usr/Android. Then I changed the SDK setting in Android Studio to point to the new location After that I also added export ANDROID_HOME="/usr/Android/Sdk" to ~/.bashrc I stopped and restarted with npm start and it recognized automatically – Daouda May 13 '23 at 00:58
2

If you create and android studio project, You can see a local.properties file is created inside your project root directory. When you create a react native project, It doesn't create that file for you. So you have to create it manually. And have to add skd dir to it. So create a new file inside android folder ( on root ). and put your sdk path like this sdk.dir=D\:\\Android\\SDK\\android_sdk_studio . Remember: remove single \ with double. Just like above.

Nouman Ghaffar
  • 3,780
  • 1
  • 29
  • 37
2

If local.properties file is missing, just create one in the "project/android" folder with 'sdk.dir=/Users/apple/Library/Android/sdk' and make sure your SDK in on that location.

for creating a file with custom extensions on mac refer the following link

How do I save a TextEdit (mac) file with a custom extension (.sas)?

2

There are 2 ways to solve this issue:

  1. Simple run your react native Android project in the android studio it will automatically generate your local.properties file in react native Android project.

  2. a. Go to React-native Project -> Android
    b. Create a file local.properties
    c. Open the file
    d. Paste your Android SDK path like below

סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68
2

Create a file with the name lcoal.properties in Android/ and paste the below path.

sdk.dir = /Users/jotnosqh/Library/Android/sdk (for linux)
Matt Andruff
  • 4,974
  • 1
  • 5
  • 21
1

Make sure you have the proper emulator and Android version installed. That solved the problem for me.

Arel
  • 3,888
  • 6
  • 37
  • 91
1

In your Project Directory there is a folder called "android" and inside it there is the local.properties file . Delete the file and the build should run successfully

Peter Hassaballah
  • 1,757
  • 1
  • 9
  • 18
1

If you are using mac you need to export your sdk path. just replace Macbook with your system name and then paste into the terminal. "For temporarily use"

export ANDROID_HOME=/Users/MacBook/Library/Android/sdk

Sumit Sharma
  • 160
  • 9
0

There are two gradle files, change the one inside your C:\myapp\android\build.gradle and not in the parent directory myapp.

Replace 23.0.1 with your version of Android Build Tool installed in my case 25.0.0

Run react-native run-android to see your app in emulator.

P.Ranjan
  • 171
  • 1
  • 6
0

Copy your system's other android project local.properties and paste in android folder of React-native project it will work.

sdk.dir=C\:\\Users\\paul\\AppData\\Local\\Android\\Sdk
Jobin
  • 5,610
  • 5
  • 38
  • 53
0

Just open folder android in project by Android Studio. Android studio create necessary file(local.properties) and download SDK version for run android needed.

Rasoul Miri
  • 11,234
  • 1
  • 68
  • 78
0

I am on Windows and I had to modify sdk path irrespective of having it in PATH env. variable

sdk.dir=C:/Users/MY_USERNAME/AppData/Local/Android/Sdk

Changed this file:

MyProject\android\local.properties
NK_Mimrot
  • 332
  • 2
  • 12
0

The problem is that you have misconfigured the environment variables. You have to use (in Windows) the SDK of: C:\Users\YOUR_USERNAME\AppData\Local\Android\Sdk

For more information: https://facebook.github.io/react-native/docs/getting-started

Select: React Native CLI Quickstart in the Android development environment section in point 3. Configure the ANDROID_HOME environment variable

If you do it as you have it right now you must configure each project to use your environment variables and if the project is among several people with their equipment it can cause a problem. If you do it as I have told you, you will not have to configure any project.

Pitel
  • 5,334
  • 7
  • 45
  • 72
IvanAllue
  • 434
  • 3
  • 11
0

If you have android studio installed, simply open the Project/android using Android Studio, and it will notify you to switch the SDK location path in the project.

FortuneCookie
  • 1,756
  • 3
  • 25
  • 41
0

This worked for me: if you have Android Studio installed, you can open your project’s Android folder in Android Studio. The local.properties file is automatically created when Android Studio opens the folder, and your project should build after that.

Open Android Studio Click “Open an Existing Project” Choose the “android” folder in your project folder Press “Open”

rdmcbath
  • 305
  • 1
  • 9
-1

After creating the local.properties file and you are still having the problem just like I was having.

Press Ctrl+S to save the file

Yeah, that was a pretty tricky miss.

  • 1
    This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/33948520) – Alon Alush Mar 05 '23 at 15:24