简体   繁体   中英

Verify that ANDROID_HOME has been added to your path

I am trying to set up react-native (for Android) on my macOs but the app is failing to build so I am retrying it by following this link:

https://reactnative.dev/docs/environment-setup

In one of the steps, we have to add something to our $HOME/.bash_profile . I open it using vi.bash_profile and then paste the commands. Next, I am asked to 'Verify that ANDROID_HOME has been added to your path by running echo $PATH. '

When I run echo $PATH. , I get this:

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Apple/usr/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Users//Library/Android/sdk/emulator:/Users//Library/Android/sdk/tools:/Users//Library/Android/sdk/tools/bin:/Users//Library/Android/sdk/platform-tools

I don't see the word ANDROID_HOME anywhere. Is there a problem here? Maybe with the path? Or is it being correctly verified?

I am running this in the root directory.

EDIT:

I managed to successfully setup everything and run the default AwesomeProject as well (from the root directory). However, when I try to run another project, it does not work. I see this:

SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project's local properties file at '/Users/mycompany/insta/app/android/local.properties

What's the problem? Which steps from the setup should I repeat inside this particular folder? Should I make another bash profile? I don't get what path to add in the local.properties

Your PATH variable is being correctly modified.

Echo your ANDROID_HOME variable to see what it is. It should be /Users//Library/Android/sdk/ . When you use this variable in PATH , it's automatically being expanded when you echo it. You won't see "ANDROID_HOME" in the PATH.

You can find all the environment variable documentation here: https://developer.android.com/studio/command-line/variables

According to the dev website:

If ANDROID_HOME is defined and contains a valid SDK installation, its value is used instead of the value in ANDROID_SDK_ROOT.

If ANDROID_HOME is not defined, the value in ANDROID_SDK_ROOT is used.

If ANDROID_HOME is defined but does not exist or does not contain a valid SDK installation, the value in ANDROID_SDK_ROOT is used instead.

Try echo $ANDROID_HOME . If that returns nothing try echo $ANDROID_SDK_ROOT . One of them should return your SDK directory. If not export one of them in your bash_profile as a env variable.

Easiest solution is to do a quick install of Android Studio and selecting the option to install SDK tools. This easily sets up your environment for android. All you need to do is add the SDK tools directory to your path once the install completes.

AVD images are pedantic if you change any directories and throw SDK_ROOT errors if you change things. Most problem free solution is to either download and run the installer or download the SDK tools, run the install and specify the path directory.

create local.properties file inside android folder and paste sdk.dir={ANDROID_SDK_PATH} , then restart react-native server.

This problem has to do with two things:

  1. local.properties file

  2. ANDROID_HOME (SDK path)

Firstly, For the local.properties, first make sure that the file is there in your project folder/android. If the file is there open it and make sure that the sdk.dir is pointing to your android SDK directory.

and if the file is not there create it and paste this:

sdk.dir = /Users/USERNAME/Library/Android/sdk

Replace USERNAME with your username

Secondly, make sure that the ANDROID_HOME is there in the system variables and is also pointing to your android SDK directory.

or create new system variable named ANDROID_HOME and set the value your android SDK directory path if it's not there

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM