Reputation: 6021
I have error when Istart 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.
How can I fix it?
Upvotes: 602
Views: 608553
Reputation: 7285
Solution:
Go to your React-native Project
Inside android folder
Create a file named --> local.properties
Open the file
paste your Android SDK path which looks similar like below
sdk.dir = C:\\Users\\USERNAME\\AppData\\Local\\Android\\sdk --> for Windows
sdk.dir = /Users/USERNAME/Library/Android/sdk --> for macOS
sdk.dir = /home/USERNAME/Android/Sdk --> for linux
Replace USERNAME
with your OS username
cd android && ./gradlew clean
cd ..
npx react-native run-android
That's it. It works!
Upvotes: 509
Reputation: 27
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.
Upvotes: -3
Reputation: 325
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”
Upvotes: 0
Reputation: 78
Create a file with the name lcoal.properties in Android/
and paste the below path.
sdk.dir = /Users/jotnosqh/Library/Android/sdk (for linux)
Upvotes: 2
Reputation: 212
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
Upvotes: 2
Reputation: 4853
I don't think it's recommended to update the local.properties
file to get to add the missing environment vars.
sdk can be installed on /Library/Android/sdk or /usr/local/ to be sure check it by
which sdkmanager
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
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
Upvotes: 71
Reputation: 1824
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
Upvotes: 83
Reputation: 2753
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.
~/.zshrc
using a code-editor. In my case I use vimvim ~/.zshrc
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.
Save the changes and close the editor.
Finally, now compile your changes
source ~/.zshrc
I get this working in my case. I hope this helps you.
Upvotes: 12
Reputation: 6984
For Windows Users
One simple solution is to set the SDK path to the Enviroment Variables list.
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.
Upvotes: 30
Reputation: 163
There are 2 ways to solve this issue:
Simple run your react native Android project in the android studio it will automatically generate your local.properties file in react native Android project.
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
Upvotes: 2
Reputation: 10548
android/
directory of your react-native projectlocal.properties
with this line:sdk.dir = /Users/USERNAME/Library/Android/sdk
Where USERNAME
is your macOS username
Upvotes: 1027
Reputation: 1865
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.
Upvotes: 0
Reputation: 637
Delete the local.properties
from the android folder in your react project and try it.
I've done this and succeeded.
Upvotes: 7
Reputation: 545
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.
Upvotes: 0
Reputation: 109
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)?
Upvotes: 3
Reputation: 45140
Updated steps for React Native0.58 to get started on MAC/Unix
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
source ~/.bash_profile
echo $PATH
adb devices
Upvotes: 29
Reputation: 352
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
Upvotes: 0
Reputation: 3830
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.
Upvotes: 2
Reputation: 1987
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
Upvotes: 1
Reputation: 3844
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
Upvotes: 28
Reputation: 1779
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
Upvotes: 5
Reputation: 12222
Just open folder android in project by Android Studio. Android studio create necessary file(local.properties) and download SDK version for run android needed.
Upvotes: 0
Reputation: 44
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
Upvotes: 0
Reputation: 7073
The best solution I can find is as follows:
This is how the gradle file will look like:
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.
Upvotes: 3
Reputation: 171
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.
Upvotes: 0
Reputation: 793
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
Upvotes: 7
Reputation: 59
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
Upvotes: 5
Reputation: 5529
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.
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.
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.
Upvotes: 17
Reputation: 3629
Check out in your local.properties
file:
sdk.dir=C\:\\Users\\USERNAME\\AppData\\Local\\Android\\sdk
if the format is proper or not
Upvotes: 6
Reputation: 2188
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
Upvotes: 11