122

I set the android_sdk_home variable so that my application could find .android when trying to run. Now I get an error stating that "android_sdk_root is undefined". I am running win 7 with a new installation of Android Studio, inside parallels on a macbook pro.

Thank you for your response. I checked the location and it is identified as the same location as the ANDROID_SDK_HOME environment path. It still says root is undefined. I created an ANDROID_SDK_ROOT enviroment path to the same location and it is still undefined.

Reed Vergin
  • 1,221
  • 2
  • 8
  • 4

15 Answers15

95

This is how I did it on macOS:

vim ~/.bash_profile  # macOS 10.14 Mojave and older
vim ~/.zshrc         # macOS 10.15 Catalina and newer (using zsh by default)

And added the following environment variables:

export ANDROID_HOME=/Users/{{your user}}/Library/Android/sdk
export ANDROID_SDK_ROOT=/Users/{{your user}}/Library/Android/sdk
export ANDROID_AVD_HOME=/Users/{{your user}}/.android/avd

Android path might be different, if so change it accordingly. At last, to refresh the terminal to apply changes:

source ~/.bash_profile  # macOS 10.14 Mojave and older
source ~/.zshrc         # macOS 10.15 Catalina and newer (using zsh by default)
Alex
  • 744
  • 8
  • 20
renatodamas
  • 16,555
  • 8
  • 30
  • 51
  • 1
    If you had an SDK installed in another location before installing Android Studio, then you may have to update the path to include the above variables first to make sure the right `sdkmanager` gets called. `export PATH=$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$PATH` – Neil Monroe May 13 '20 at 17:15
  • 7
    ```export ANDROID_HOME=$HOME/Android/Sdk export ANDROID_SDK_ROOT=$HOME/Library/Android/sdk export ANDROID_AVD_HOME=$HOME/.android/avd``` – Yauhen Yakimovich Jun 25 '20 at 17:45
  • I was doing the same thing but was not refreshing the terminal, thanks for the advice – aliraza12636 Oct 08 '20 at 14:53
50

I received the same error after installing android studio and trying to run hello world. I think you need to use the SDK Manager inside Android Studio to install some things first.

android_sdk_root error

Open up Android Studio, and click on the SDK Manager in the toolbar.

SDK Manager

Now install the SDK tools you need.

  • Tools -> Android SDK Tools
  • Tools -> Android SDK Platform-tools
  • Tools -> Android SDK Build-tools (highest version)

For each Android release you are targeting, hit the appropriate Android X.X folder and select (at a minimum):

  • SDK Platform
  • A system image for the emulator, such as ARM EABI v7a System Image

The SDK Manager will run (this can take a while) and download and install the various SDKs.

Inside Android Studio, File->Project Structure will show you where your Android sdks are installed. As you can see mine is c:\users\Joe\AppData\Local\Android\sdk1.

enter image description here

If I navigate to C:\Users\Joe\AppData\Local\Android\sdk1\sources you can see the various Android SDKs installed there...

SDK Directories

Joe Healy
  • 5,769
  • 3
  • 38
  • 56
47

Open the terminal and run the command: nano $HOME/.bashrc aggregate the follow line:

export ANDROID_HOME=$HOME/Android/Sdk
export ANDROID_SDK_ROOT=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform-tools

Ctrl+o save and ctrl+x close.

And run the command:

source $HOME/.bashrc

echo $ANDROID_SDK_ROOT
Leonardo Pineda
  • 990
  • 8
  • 10
21

MAC - one liner

echo "export ANDROID_HOME=~/Library/Android/sdk \
      export ANDROID_SDK_ROOT=~/Library/Android/sdk \
      export ANDROID_AVD_HOME=~/.android/avd" \
>> ~/.bash_profile && source ~/.bash_profile
Proximo
  • 6,235
  • 11
  • 49
  • 67
16

android_sdk_root is a system variable which points to root folder of android sdk tools. You probably get the error because the variable is not set. To set it in Android Studio go to:

  1. File -> project Structure into Project Structure
  2. Left -> SDK Location
  3. SDK location select Android SDK location

If you have installed android SDK please refer to this answer to find the path to it: https://stackoverflow.com/a/15702396/3625900

Community
  • 1
  • 1
Sebas Hollow
  • 173
  • 1
  • 1
  • 8
12

In addition to the above answers, ANDROID_HOME, which also points to the SDK installation directory, is deprecated. If you continue to use it, the following rules apply:

  • 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.
Pankaj Sati
  • 2,441
  • 1
  • 14
  • 21
10

You need to make a system env variable with the name: ANDROID_SDK_ROOT and it's value should be C:\Users\your_user_name\AppData\Sdk\tools\bin worked for me

Osher Vaknin
  • 99
  • 1
  • 3
7

ANDROID_HOME

Deprecated (in Android Studio), use ANDROID_SDK_ROOT instead.

ANDROID_SDK_ROOT

Installation directory of Android SDK package.

Example: C:\AndroidSDK or /usr/local/android-sdk/

ANDROID_NDK_ROOT

Installation directory of Android NDK package. (WITHOUT ANY SPACE)

Example: C:\AndroidNDK or /usr/local/android-ndk/

ANDROID_SDK_HOME

Location of SDK related data/user files.

Example: C:\Users\<USERNAME>\.android\ or ~/.android/

ANDROID_EMULATOR_HOME

Location of emulator-specific data files.

Example: C:\Users\<USERNAME>\.android\ or ~/.android/

ANDROID_AVD_HOME

Location of AVD-specific data files.

Example: C:\Users\<USERNAME>\.android\avd\ or ~/.android/avd/

JDK_HOME and JAVA_HOME

Installation directory of JDK (aka Java SDK) package.

Note: This is used to run Android Studio(and other Java-based applications). Actually when you run Android Studio, it checks for JDK_HOME then JAVA_HOME environment variables to use.

Yousha Aleayoub
  • 4,532
  • 4
  • 53
  • 64
4

For macOS with zshrc:

ANDROID_HOME is depreciated, use ANDROID_SDK_ROOT instead

  1. Ensure that Android Build Tools is installed. Check if it exists in your File Directory
  2. Get the path to your SDK. Usually it is /Users/<USER>/Library/Android/sdk
  3. Add ANDROID_SDK_ROOT as a path to your Environment variables: echo 'export ANDROID_SDK_ROOT=/Users/<USER>/Library/Android/sdk' >> ~/.zshenv
  4. Apply the changes with source ~/.zshrc
  5. Check if it was saved by ...
    • ... checking the specific environment variable echo $ANDROID_SDK_ROOT
    • ... checking the complete list of environment variables on your system env

You can apply this process to every environment variable beeing installed on your macOS system. It took me a while to comprehend it for myself

Ljonja
  • 197
  • 9
  • 1
    According to the documentation at https://developer.android.com/studio/command-line/variables#envar it is actually the other way round. Use `ANDROID_HOME`. The environment variable `ANDROID_SDK_HOME` is deprecated. Some tools like Android Studio and Android Gradle plugin check if they are consistent if both are present. – Manfred Jun 06 '22 at 05:54
4

on Mac edit .bash_profile use code or vim

code ~/.bash_profile

export ANDROID_SDK_ROOT=~/Library/Android/sdk

export ANDROID_HOME=~/Library/Android/sdk
faye
  • 95
  • 7
1

In Android Studio 3.2.1 I got this error because I installed a new API(28) level emulator without installing that API SDK components. After I installed SDK platform and SDK platform tools for the API level 28 and updated Android Emulator the emulator started running.

Hope it may help someone.

Mahendran Sakkarai
  • 8,381
  • 6
  • 44
  • 66
1

This is how to change it :

Step 1 :

Open a Terminal / CMD As Administrator (Right-click on cmd and click "Run as Administrator")

Step 2:

type in " set ANDROID_SDK_ROOT=E:\Android\sdk\ " (type it without the quotes and replace "E:\Android\sdk" with your actual sdk file path location - Mine was : C:\Users\YOUR_ACCOUNT\AppData\Local\Android\Sdk

step 3:

Press "Enter" and i noticed nothing happened

Step 4:

Build your app again and it should reflect your file path. For me it doisplayed as :

Preparing Firebase on Android Checking Java JDK and Android SDK versions ANDROID_SDK_ROOT=C:\Users\Kurt\AppData\Local\Android\Sdk (recommended setting) ANDROID_HOME=C:\Users\Kurt\AppData\Local\Android\Sdk (DEPRECATED) Subproject Path: CordovaLib Subproject Path: app

I got that info from this site :

https://developer.android.com/studio/command-line/variables#android_sdk_root

Check it out for more information Have Fun!!

Kurt
  • 11
  • 1
0

on mac os you can try brew install gradle

0

I followed this tutorial to set up my android environment variables I was on mac and I had all the required environmental variable setup and working already. but i was still getting this error that requires environment ANDROID_SDK_ROOT.

I already had an android SDK exported environment variable.

So, what I simply did is adding ANDROID_HOME to the path with the following commands: export PATH=$PATH:$ANDROID_HOME

and it worked for me on macOS

Kashan Haider
  • 1,036
  • 1
  • 13
  • 23
-1

A common mistake that people tend to make when setting the root is capitalization errors in the path, or accidental spacing. Hence, I would recommend you check that. If that does not solve it, then check if the folder you are linking to still exists, or was accidentally moved into the trash.

RajaSJN
  • 11
  • 3