2

I looked all over Google and Stack Overflow for an answer, but I couldn't find the right one for me. I am learning Cordova and I'm trying to run the android emulator through terminal, and when I run 'sudo cordova emulate android' I get this message:

''Failed to find 'ANDROID_HOME' environment variable. Try setting it manually. Detected 'avdmanager' command at /Users/username/Library/Android/sdk/cmdline-tools/latest/bin but no 'tools/bin' directory found near. Try reinstall Android SDK or update your PATH to include valid path to SDK/tools/bin directory.''

But I set the variables in the ~./bash_profile file and it looks like this:

export ANDROID_HOME="/Users/username/Library/Android/sdk"

export ANDROID_SDK_ROOT=$ANDROID_HOME

export PATH=${PATH}:$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools

export PATH=${PATH}:$ANDROID_HOME/tools/bin

export PATH="$PATH:$ANDROID_HOME/build-tools/30.0.0-rc2"

I am using a MacOS Mojave, does anyone know what the issue is? Thanks in advance

  • Does this answer your question? [Setting ANDROID\_HOME enviromental variable on Mac OS X](https://stackoverflow.com/questions/19986214/setting-android-home-enviromental-variable-on-mac-os-x) – Reza Dehnavi Mar 23 '20 at 20:56
  • Have you ever seen [this post](https://stackoverflow.com/questions/19986214/setting-android-home-enviromental-variable-on-mac-os-x) – Reza Dehnavi Mar 23 '20 at 20:56
  • @RezaDehnavi thanks for the help, it still doesn't work, I'll try it on Windows. – Leon Grubisic Mar 26 '20 at 09:42

1 Answers1

0

Apparently, in the latest version of Android Studio, the old SDK tools (under /tools, which Cordova seems to expect) are already considered obsolete. There is a solution documented here on how to install the old version of SDK tools.

  • Open Android Studio
  • Open Tools -> Sdk Manager
  • Click on the Sdk Tools Tab
  • Uncheck Hide Obsolete Packages
  • Check Android Sdk Tools (Obsolete)
  • Click Apply

This should download the old SDK tools under the correct folder.

However, I think Cordova also needs to keep up with the newest Android development tools. There's another change I needed to make after this:

I had to delete the tools/emulator and tools/emulator-check binaries, and add $ANDROID_HOME/emulator to my $PATH, since the current emulator binary lives under emulator/emulator instead of path/emulator. See this post.

Then I was finally able to launch the app directly via Cordova.

xji
  • 5,835
  • 4
  • 32
  • 54