51

I am trying to use Cordova for mobile app development. For now I am focusing on Android. I am trying to run cordova emulate android. It runs and after a long list of packages it says ‘build successful’ but in the end it also says:

PANIC: Cannot find AVD system path. Please define ANDROID_SDK_ROOT

I use Homebrew. Here is output of the command:

BUILD SUCCESSFUL

Total time: 1.345 secs
Built the following apk(s):
    /users/mayurtolani/myMobileApp/platforms/android/build/outputs/apk/android-debug.apk

ANDROID_HOME=/usr/local/Cellar/android-sdk/24.4.1_1
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home
No emulator specified, defaulting to Nexus_5_API_24
Waiting for emulator to start...
PANIC: Cannot find AVD system path. Please define ANDROID_SDK_ROOT
Mehdi Charife
  • 722
  • 1
  • 7
  • 22
Mayur Tolani
  • 1,458
  • 3
  • 17
  • 28
  • Did you install the Android SDK via homebrew? If so, try the steps outlined [here](http://stackoverflow.com/a/19986294/483658). – Erik Oct 25 '16 at 20:10
  • just install android studio for mac, it will install all you need automatically and you will have no problems with avd system path. – Stepan Maksymov Oct 25 '16 at 20:17
  • As far as using the Genymotion emulator and having the Google Apps installed on it, check out [this guide](https://guides.codepath.com/android/Genymotion-2.0-Emulators-with-Google-Play-support) on Codepath. – Erik Oct 25 '16 at 20:42
  • try the answer http://stackoverflow.com/a/39711435/2808137 – Mahmoud Hboubati Jan 10 '17 at 17:53

9 Answers9

100
vim ~/.bash_profile

Then add the following environment variables:

export ANDROID_HOME=~/Library/Android/sdk
export ANDROID_SDK_ROOT=~/Library/Android/sdk
export ANDROID_AVD_HOME=~/.android/avd

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

source ~/.bash_profile
Community
  • 1
  • 1
renatodamas
  • 16,555
  • 8
  • 30
  • 51
  • That happened to work for me, so thanks. But it is one of 3 popular locations according to https://stackoverflow.com/questions/19986214/setting-android-home-enviromental-variable-on-mac-os-x/ – MarkHu Mar 05 '18 at 23:58
  • this solution perfectly work for me . just need to restart your mac after editing the file – Umar Abbas Jul 27 '18 at 18:55
  • 1
    @UmarAbbas Mac is not a Windows, you don't need to restart it every 5 minutes... As in answer stated at the end, just use `source` command – biesior Sep 29 '20 at 02:59
  • @biesior correct, if you restart your mac every time you make some config, you're gonna have a hard time. – renatodamas Sep 30 '20 at 06:37
  • @RenatoDamas the best way is when soft developer... uses his brain ;) a lot of things can be loaded without forcing end-users to reboot. Otherwise, the very first thing I always try if there's no other option is just logging-off an on, without rebooting. In most cases works. Of course in case of simple `source your-file` we don't have this problem. – biesior Sep 30 '20 at 10:44
  • @biesior indeed, except if you're on a Windows. In that case you're just better off rebooting :) – renatodamas Sep 30 '20 at 14:49
  • @RenatoDamas, would you mind addressing a similar issue I'm having. I'm not sure what to do at this point. https://stackoverflow.com/questions/65375107/how-would-i-update-my-android-sdk-root-java-home-path-environment-variables – D.Hodges Dec 19 '20 at 23:02
  • It seems the 3rd one is not valid anymore at the moment of this writing – George Pligoropoulos Aug 08 '21 at 12:24
16

Since you used Homebrew, you can add this to your path:

export ANDROID_SDK_ROOT=/usr/local/share/android-sdk

Hope I helped! :D

Rodrigo Chaves
  • 1,094
  • 8
  • 23
16

I was facing similar problem. I already downloaded Android SDK as well as Android studio so there were two paths of Android Home. To run emulator and remove error of Android sdk root not set use below steps.

  1. Set the path of android sdk which is downloaded by Android Studio.
  2. If you already have SDK downloaded in sdk folder copy them in Android studio generated folder. /Library/Android/sdk
  3. Set the bash profile and add paths as shown below.

    export ANDROID_HOME=/Users/{your pc name}/Library/Android/sdk
    export ANDROID_SDK_ROOT=$ANDROID_HOME
    
grg
  • 5,023
  • 3
  • 34
  • 50
Suraj
  • 317
  • 4
  • 7
8

Update 2021

If you are a hybrid cordova/ionic/react app developer. Here's what worked for me. All the other answers failed. So i'm sharing my answer

1. Find the correct JAVA_HOME path on your machine

/usr/libexec/java_home -V

2. Copy that path associated with "Java SE 8" which usually looks like /Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home

3. create a ~/.bash_profile or ~/.zshrc file. Here I'm using touch because I dislike nano or vim in the terminal. touch is a regular text editor which I'm more comfortable editing with. Use whatever you like.

   touch ~/.bash_profile;
    
   touch ~/.zshrc;

4. edit and copy/paste this in your ~/.bash_profile or ~/.zshrc file

export PATH=$PATH:$ANDROID_HOME/platform-tools  
export ANDROID_SDK_ROOT=/Users/user198559/Library/Android/sdk
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_251.jdk/Contents/Home

5. Save your file with file->save like you would save any regular file, after that write this in your terminal

source ~/.bash_profile;

source ~/.zshrc;

6. check if path variables are set correctly by opening new terminal

echo $JAVA_HOME

/Library/Java/JavaVirtualMachines/jdk1.8.0_251.jdk/Contents/Home

echo $ANDROID_SDK_ROOT

/Users/user198559/Library/Android/sdk

echo $ANDROID_HOME (deprecated)

(should return empty)
Grogu
  • 2,097
  • 15
  • 36
  • Hi, I followed the same steps as you mentioned but if I quit my terminal and reopen and check "echo $ANDROID_SDK_ROOT" it returns empty. but after running "source ~/.bash_profile" it showing the path. is there any way to fix permanently this? – Akash Mishra Nov 29 '22 at 08:58
6

In addition to Grogu's answer, try this paths. It worked for my M1 mac. Make sure you have Android Studio installed.

export JAVA_HOME=$(/usr/libexec/java_home -v 1.8.0)

#SDK exporting
export ANDROID_HOME=$HOME/Library/Android/sdk

#Tools exporting
export PATH=$PATH:$ANDROID_HOME/emulator:$PATH
export PATH=$PATH:$ANDROID_HOME/tools:$PATH
export PATH=$PATH:$ANDROID_HOME/tools/bin:$PATH
export PATH=$ANDROID_HOME/platform-tools:$PATH
Vlad R
  • 1,851
  • 15
  • 13
  • after some time I had to update java on my mac, in order to do that I had to replace the first line with the following: `export JAVA_HOME=$(/usr/libexec/java_home -v 11.0.17)`. Prior to do that, make sure you installed java 11. *Be careful with versioning*. – Vlad R Dec 26 '22 at 09:26
2

ANDROID_HOME is necessary also, it should be same as ANDROID_SDK_ROOT. FYI:you need restart Android Studio after you changed your .bash_profile.

Akshay
  • 2,506
  • 4
  • 34
  • 55
gonghua
  • 21
  • 2
1

Today I had the same problem with ionic framework. First, I checked in AVD manager in Android Studio(tools->Android) that all devices run and it was one device without api version. So I changed and test the device. Then i run ionic emulate again and works fine. Also, you could use --target=Device_Name to run a specific device.

0

In my New Macbook air M1 I am using Android Bumblebee version got the same issue so below is the step which helped me

Go to File -> Project structure -> On the left side menu SDK Location -> at the bottom of SDK Location section click on Gradle Settings which would be in blue colour -> A Gradle dialog will pop up then click on the Gradle JDK dropdown and select "Android Studio java home" and click on okay.

Then click on Build menu on top -> Clean Project Then click on Build menu on top -> Rebuild Project

Run the app again error might have gone Hope this would have helped

Rahul
  • 99
  • 6
-1

In my OSX terminal, i have avoided this error by manually adding the name of the Virtual device that i can read under "AVD name" from AVD manager.

ionic emulate android --target="AVD name"
Nicolas Guérinet
  • 2,086
  • 1
  • 29
  • 38