116

When I run ionic build android command in root of ionic project, I am getting this error:

FAILURE: Build failed with an exception.

  • Where: Script '/home/javad/Desktop/javadApp/platforms/android/CordovaLib/cordova.gradle' line: 64

  • What went wrong: A problem occurred evaluating root project 'android'.

    No installed build tools found. Please install the Android build tools version 19.1.0 or higher.

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

javad@javad:~/Desktop/javadApp$ ionic build android
Running command: /home/javad/Desktop/javadApp/hooks/after_prepare/010_add_platform_class.js /home/javad/Desktop/javadApp
add to body class: platform-android
Running command: /home/javad/Desktop/javadApp/platforms/android/cordova/build 
ANDROID_HOME=/opt/android-sdk
JAVA_HOME=/usr/lib/jvm/default-java
Running: /home/javad/Desktop/javadApp/platforms/android/gradlew cdvBuildDebug -b /home/javad/Desktop/javadApp/platforms/android/build.gradle -Dorg.gradle.daemon=true

FAILURE: Build failed with an exception.

* Where:
Script '/home/javad/Desktop/javadApp/platforms/android/CordovaLib/cordova.gradle' line: 64

* What went wrong:
A problem occurred evaluating root project 'android'.
> No installed build tools found. Please install the Android build tools version 19.1.0 or higher.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 1.564 secs

/home/javad/Desktop/javadApp/platforms/android/cordova/node_modules/q/q.js:126
                    throw e;
                          ^
Error code 1 for command: /home/javad/Desktop/javadApp/platforms/android/gradlew with args: cdvBuildDebug,-b,/home/javad/Desktop/javadApp/platforms/android/build.gradle,-Dorg.gradle.daemon=true
ERROR building one of the platforms: Error: /home/javad/Desktop/javadApp/platforms/android/cordova/build: Command failed with exit code 8
You may not have the required environment or OS to build this project
Error: /home/javad/Desktop/javadApp/platforms/android/cordova/build: Command failed with exit code 8
    at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:134:23)
    at ChildProcess.EventEmitter.emit (events.js:98:17)
    at maybeClose (child_process.js:743:16)
    at Process.ChildProcess._handle.onexit (child_process.js:810:5)

in ~/.profile i have:

export PATH=$PATH:/opt/android-sdk/tools

export PATH=$PATH:/opt/android-sdk/platform-tools

export PATH=$PATH:/opt/node/bin

export JAVA_HOME=/usr/lib/jvm/default-java

export ANDROID_HOME=/opt/android-sdk

$PATH is:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/opt/android-sdk/tools:/opt/android-sdk/platform-tools:/opt/node/bin

Important issue:

in file: /home/javad/Desktop/javadApp/platforms/android/CordovaLib/cordova.gradle | line 38:

String[] getAvailableBuildTools() {
    def buildToolsDir = new File(getAndroidSdkDir(), "build-tools")
    buildToolsDir.list()
        .findAll { it ==~ /[0-9.]+/ }
        .sort { a, b -> compareVersions(b, a) }
}

just returned /opt/android-sdk/build-tools !!!

in /opt/android-sdk/build-tools folder i have:

android-5.1 folder that extract from: https://dl.google.com/android/repository/build-tools_r22-linux.zip

lmiguelvargasf
  • 63,191
  • 45
  • 217
  • 228
javad75
  • 1,415
  • 2
  • 11
  • 13
  • Its Working for me check http://stackoverflow.com/questions/38660955/ionic-cordova-in-android-studio-no-installed-build-tools-found – vinod Feb 07 '17 at 09:42

33 Answers33

72

I fix this by downloading sdk package called platform-tools and buid-tools using sdkmanager. You can use sdkmanager.exe or if you are using SDK CLI, go to ~\AppData\Local\Android\sdk\tools\bin and run this command:

sdkmanager "platform-tools" "platforms;android-26"

or

sdkmanager "build-tools;27.0.3"

or both

After that you should be able to run ionic cordova run android or ionic build android.

Note: globalize sdkmanager command by adding ~\AppData\Local\Android\sdk\tools and ~\AppData\Local\Android\sdk\tools\bin to your environment variable.

Fadhil Ahmad
  • 1,097
  • 11
  • 19
  • 4
    Don't forget to run cmd as Administrator to avoid errors. I faced Warning: "Failed to read or create install properties file" error – kkost Jun 06 '18 at 14:27
  • Thank you, this was an essential step for me in the build process. – Barry Nov 26 '18 at 16:15
  • opened terminal within the bin folder: says sdkmanager: command not found – MJ Montes Apr 29 '19 at 08:09
  • @LasLemieux please check if you install the SDK CLI properly. If u are using windows, there should have a file named sdkmanage.exe. – Fadhil Ahmad Apr 29 '19 at 09:47
  • This worked for me but I had to add --sdk_root option to prevent the following error: Observed package id 'tools' in inconsistent location '/opt/cmdline-tools/tools' (Expected '/opt/tools') – Cédric VIDREQUIN Apr 22 '21 at 13:46
65

For me running these three commands fix the issue on my Mac:

export ANDROID_HOME=~/Library/Android/sdk
export ANDROID_SDK_ROOT=~/Library/Android/sdk
export PATH=${PATH}:${ANDROID_HOME}/tools
export PATH=${PATH}:${ANDROID_HOME}/platform-tools

For ease of copying here's one-liner

export ANDROID_HOME=~/Library/Android/sdk && export PATH=${PATH}:${ANDROID_HOME}/tools && export PATH=${PATH}:${ANDROID_HOME}/platform-tools && export ANDROID_SDK_ROOT=~/Library/Android/sdk

To add Permanently

Follow these steps:

  1. Open the .bash_profile file in your home directory (for example, /Users/your-user-name/.bash_profile) in a text editor.
  2. Add export PATH="The above exports here" to the last line of the file, where your-dir is the directory you want to add.
  3. Save the .bash_profile or .zshrc file.
  4. Restart your terminal. Or run source ~/.bash_profile or source ~/.zshrc depending on your terminal settings.

Adding to bash process for different systems

Black Mamba
  • 13,632
  • 6
  • 82
  • 105
  • 3
    This helps me every time, but as soon as I close terminal or restart the mac, I need to do this again – Forza Nov 21 '18 at 14:29
  • This worked for me. @Forza if you add it to your ~/.bash_profile it will work everytime. – caden311 Apr 16 '19 at 19:59
  • I mistakenly had those PATH subdirectories appended to my ANDROID_HOME variable. Once I cleaned this up, it worked! – umbyersw Jun 30 '19 at 21:29
  • How do you make it that you dont have to re rerun the command every time you restart the terminal? – Ross Rawlins Oct 15 '19 at 09:53
  • I tried that but it doest stick I have to do it every time I open terminal. – Ross Rawlins Oct 23 '19 at 07:40
  • Can you please go through https://stackoverflow.com/questions/22465332/setting-path-environment-variable-in-osx-permanently and let me know if any of that works for you I'll add that to answer here as it's currently working for me @RossRawlins – Black Mamba Oct 23 '19 at 07:44
  • 2
    To permanently install in mac paste this in both files: 'nano ~/.zshrc' and 'touch . bash_profile' – David Santiago Nov 02 '21 at 18:07
  • ANDROID_HOME is deprecated, use ANDROID_SDK_ROOT instead – José Manuel Blasco Dec 29 '21 at 15:06
  • 1
    Thank you @manuman94 just updated my answer can you please have a look if it's fine – Black Mamba Dec 29 '21 at 16:05
  • Yes! That should work! But I would remove the old ANDROID_HOME as its use is discouraged: https://developer.android.com/studio/command-line/variables#envar Greetings! – José Manuel Blasco Dec 30 '21 at 19:41
  • The `ANDROID_SDK_ROOT` pointing to the SDK we are using on Android Studio is the trick. Having that environment variable fixes the problem of not knowing where to look for the build tools. – Joel Carneiro Aug 29 '22 at 13:26
31

You are missing android SDK tools. Please try the following:

android list sdk --all
android update sdk -u -a -t <package no.>

Where <package no.> is 1,2,3,n and

-u (--no-ui)  # Headless mode
-a (--all)    # Includes all packages (also obsolete ones)
-t (--filter) # Filter by package index
Aley
  • 8,540
  • 7
  • 43
  • 56
22

as the error says 'No installed build tools found' it means that

1 : It really really really did not found build tools

2 : To make him find build tools you need to define these paths correctly

export ANDROID_HOME=/Users/vijay/Software/android-sdk-macosx
export PATH=${PATH}:/Users/vijay/Software/android-sdk-macosx/tools
export PATH=${PATH}:/Users/vijay/Software/android-sdk-macosx/platform-tools

3 : IMPORTANT IMPORTANT as soon as you set environmental variables you need to reload evnironmental variables.

//For ubuntu
$source .bashrc 

//For macos
$source .bash_profile

4 : Then check in terminal

$printenv ANDROID_HOME
$printenv PATH

Note : if you did not find your changes in printenv then restart the pc and try again printenv PATH, printenv ANDROID_HOME .There is also command to reload environmental variables .

4 : then open terminal and write HALF TEXT '$and' and hit tab. On hitting tab you should see full '$android' name.this verifys all paths are correct

5 : write $android in terminal and hit enter

Community
  • 1
  • 1
vijay
  • 10,276
  • 11
  • 64
  • 79
18

Please install the Android build tools version 19.1.0 or higher.

The following commands can update Android SDK on Ubuntu quickly and fix the above error:

android list sdk --all
android update sdk -u -a -t 19
android update sdk -u -a -t 20
Wasim
  • 1,146
  • 11
  • 25
17

I fix the error by changing the ANDROID_HOME to C:\Users\Gebru\AppData\Local\Android\Sdk from wrong previous directory.

Gebru Welay
  • 367
  • 4
  • 8
  • This worked for me. I didn't have `ANDROID_HOME` set and Cordova assumed it was at `/usr/lib/android-sdk` which was incorrect – hughjdavey Feb 27 '18 at 12:47
  • I have the same, except I stopped before /Sdk. Seems anything wrong with that line breaks it – Low Jun 28 '18 at 11:24
7

I know this doesn't look related, especially given the error message, but I fixed this by installing a newer version of the Android SDK Build tools.

RB_
  • 799
  • 5
  • 10
7

2018

The "android" command is deprecated.

try

sdkmanager "build-tools;27.0.3"

This work for me, as #Fadhil said

6

In my case, the Enviroument Variable ANDROID_HOME was pointed to wrong (old) directory. I reallocated to correct one. In my case

ANDROID_HOME=F:\Program Files (x86)\Android\android-sdk

robie2011
  • 3,678
  • 4
  • 21
  • 20
6

For me, the problem was that ANDROID_HOME was pointing to an old Android SDK path. After installing Android Studio, I had to update ~/.bash_profile accordingly for MAC (El Capitan)

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

Remember to re-start terminal or run this command after updating ~/.bash_profile

source ~/.bash_profile

Cœur
  • 37,241
  • 25
  • 195
  • 267
5

FOR WINDOW: I have faced this type of issue. But after exploring it solved in my case. I am using window 10. just follow few steps below:

  1. download Android SKD Manager for windows. https://developer.android.com/studio at the end of this page. It is zip file. after extracting it will show tools directory.

  2. Go to drive C:\ create new folder 'android-sdk'. copy tools folder and past in
    C:\android-sdk

  3. open command prompt as Administrator. Go to cd " c:\android-sdk\tools\bin ". sdkmanager will be show here. type skdmanager, it will show like this [=======================================] 100% Computing updates...

  4. after that type "sdkmanager platform-tools" it will create platform-tools directory in C:\android-sdk

  5. Now set System environment variables: right click on PC select properties. system settings will popup. click on > Environment Variables. Environment Variables will popup.

  6. At this window System variables as like this. C:\android-sdk\platform-tools and C:\android-sdk\tools\bin

  7. run command to build tools sdkmanager "build-tools;27.0.3"

    Also make sure java path is defined. I hope it will solve problem.

Community
  • 1
  • 1
MAzeem
  • 81
  • 1
  • 3
5

I Search this problem for days.... I hope it will be usefull

FINAL SOLUTION: (I assume that you have installed Oracle-JDK and ANDROID)

open /etc/environment with

 sudo nano /etc/environment


PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/shoniisra/Android/Sdk/tools:/home/shoniisra/Android/Sdk/platform-tools:/home/shoniisra/Android/Sdk/build-tools:/home/shoniisra/Android/Sdk:/home/shoniisra/android-studio/bin"
JAVA_HOME="/home/shoniisra/java/jdk1.8.0_231"
ANDROID_HOME="/home/shoniisra/Android/Sdk/build-tools/29.0.2"
ANDROID_SDK_ROOT="/home/shoniisra/Android/Sdk"
ANT_HOME="/home/shoniisra/ant/apache-ant-1.9.14"

Save and exit (CTRL+o CTRL+X)

Reload file source /etc/environment

If you recently installed Android you should accept some licences

cd ~/Android/Sdk/tools/bin/

Execute sdkmanager:

./sdkmanager --licenses

Then Accept all, and Finally generate your APK

cd {yourproyect}
sudo ionic cordova build android
Shoniisra
  • 621
  • 7
  • 6
4

Type android on your command line and install "Android SDK Build-tools"

Karan Bhutwala
  • 777
  • 10
  • 17
3

I have solved this issue by following steps:

  1. Go to cordova.gradle file (platform/android/cordovaLib/cordova.gradle)
  2. Search for getAndroidSdkDir() method
  3. Now simply replace System.getenv("ANDROID_HOME") with your real Android SDK path
Rakshita
  • 61
  • 3
2

In build.gradle script it checks if build-tools version is lower than maxVersion from Gradle configuration. So in my case, I had environment SDK vars set, but my version was higher than allowed.

def highestBuildToolsVersion = buildToolsDirContents
    .collect { new Version(it) }
    // Invalid inputs will be handled as 0.0.0
    .findAll { it.isHigherThan('0.0.0') && it.isLowerThan(maxVersion) }
    .max()
  • That was the problem in my case, you just have to go to Android SDK Manager --> SDK Tools, then check "Show Package Details" and install missing versions. – rjp78 Mar 09 '22 at 10:55
1

This problem I solved with the following detail, somehow the android SDK manage installed all the dependencies and necessary files, but forget this `templates` files where is found templates> gradle> wrapper. This set of files is missing.

Screenshot

Path in mac /Users/giogio/Library/Android/sdk/tools/templates

tomerpacific
  • 4,704
  • 13
  • 34
  • 52
1

I added <preference name="android-minSdkVersion" value="19" /> to my conf.xml and the build was successful.

Narek Tootikian
  • 1,323
  • 2
  • 9
  • 15
1

In my case the problem was that ANDROID_HOME was pointing to ~/Library/Android/ for some reason. The correct path is ~/Library/Android/sdk

miqrc
  • 1,964
  • 2
  • 18
  • 24
1

I had the same problem. I tried all the solutions on this page, but what worked for me was installing the EXACT version of build-tools requested. In my case, I had a later version installed(33.0.0), but in order to make it work I had to download an older one 30.0.3.

mmdfl
  • 61
  • 8
0

This works for me! be careful with the new java versions because they cause error, check that you have everything installed and in your specific directory,

I did not use openJDK

export JAVA_HOME="/usr/lib/jvm/java-8-jdk" \
&& export PATH=$JAVA_HOME/bin:$PATH \
&& export ANDROID_HOME=$HOME/Android/Sdk \
&& export PATH=${PATH}:${ANDROID_HOME}/tools \
&& export PATH=${PATH}:${ANDROID_HOME}/platform-tools \
&& export GRADLE_HOME=/usr/share/java/gradle/bin/gradle \
export PATH=$PATH:$GRADLE_HOME/bin

Linux 4.14.39-1-MANJARO #1 SMP PREEMPT Wed May 2 19:03:39 UTC 2018 x86_64 GNU/Linux

see the screenshot in my shell

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
0

The solution for this question is here https://docops.ca.com/devtest-solutions/8-0-2/en/installing/setting-up-the-mobile-testing-environment/preinstallation-steps-for-mobile-testing/

Please follow this steps, and solve your problem.

The Android SDK package contains a component called compile tools. The mobile test requires at least version 19.0.1, 19.1.0 or 20.0.0.

If these versions are not installed with your ADT package, you may receive an error message when creating a mobile asset in the DevTest Workstation:

Kingsley
  • 14,398
  • 5
  • 31
  • 53
0

Mac IOS

Edit ~/.bash_profile by using vi or other shell editor

vi ~/.bash_profile

Add the following lines:

export ANDROID_HOME=~/Library/Android/sdk
export PATH=${PATH}:~/Software/android-sdk-macosx/tools:~/Software/android-sdk-macosx/platform-tools"

(save the file, and exit) load those updated env variables to the current shell env:

. ~/.bash_profile
  • If from some reason you have an old version of the build tools, you can update them from the android development studio:
  • Configure --> SDK Manager --> select "Android SDK Build-Tools
  • Check the "Show Package details"
  • review the versions of this package, update if needed
Eyal c
  • 1,573
  • 1
  • 11
  • 8
0

Well Many people give their answer, some answer is same, some answer id different. I try many answer but they are did not work for me, of course I try from above answer also but did not solve my issue. And I don't know why but I have the same error even my issue solved by this ANSWER. I just want to write it might be helpful for someone.

user9088454
  • 1,076
  • 1
  • 15
  • 45
0

I have tried all the above solution. None works. Until I was linked to https://forum.ionicframework.com/t/ionic-v4-no-installed-build-tools-found/152150.

Apparently, you must run the command as root. Sudo is not enough. You need to change to root user before you can run all the commands.

Apit John Ismail
  • 2,047
  • 20
  • 19
0

Open Command Prompt Check for ANDROID_HOME path using SET ANDROID_HOME, if not set then set using below command.

 SET ANDROID_HOME="C:\Users\VenkateshMogili\AppData\Local\Android\Sdk"

OR open system environment variables and create new variable as

 Variable Name: ANDROID_HOME
 Variable Value: C:\Users\VenkateshMogili\AppData\Local\Android\Sdk

and open cordova.gradle file (/platforms/android/CordovaLib/cordova.gradle) and search for getAndroidSdkDir() method and Replace the ANDROID_HOME path ("C:/Users/VenkateshMogili/AppData/Local/Android/Sdk") instead of System.getenv("ANDROID_HOME")

If license problem arises then type below command by opening the command prompt in C:\Users\VenkateshMogili\AppData\Local\Android\Sdk\tools\bin

  sdkmanager "build-tools;27.0.3"  //<-that will create build-tools folder and licenses folder.

It works for me.

VenkateshMogili
  • 591
  • 4
  • 5
  • Isn't the fifth line of the log OP posted already showing that `ANDROID_HOME` is set (to `/opt/android-sdk`)? – LWChris Dec 08 '19 at 19:33
  • Once check in your Home Directory, mostly it could be present in Home /home/username/Android/sdk Try to set that if it found. paste the below line at the end of the .bashrc file(in home directory) export ANDROID_HOME=$HOME/Android/Sdk – VenkateshMogili May 11 '20 at 20:37
0

Warning for developers using Virtual Machines

I spent a very long time trying to resolve this issue. I tried everything in this post and many more solutions on the web. However, after many failures and going through what everyone on the web was saying I still couldn't resolve the issue on my VM - which is a Windows 10 image on VMWare Workstation.

After reviewing all the solutions and descriptions of machines/operating systems people were developing on the glaring difference in my setup was I was developing in a VM.

Solution: I pulled all my code onto the host machine (Windows 10 OS), reinstalled all the dependencies, and sure as heck it all worked out first go around. After a lot of research I found some warnings that Android Studio has some known issues around installing properly in some VMs. So if you were like me & tried all solutions (many times over) and nothing worked, but you're in a VM, you may need to consider building on your host (or other physical machine)

marshall legend
  • 474
  • 1
  • 6
  • 13
0

This issue also occur if you do an upgrade to you cordova installation.

Check if your log error has something like:

Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=undefined (recommended setting) <-------------
ANDROID_HOME=/{path}/android-sdk-linux (DEPRECATED)
Using Android SDK: /usr/lib/android-sdk
Starting a Gradle Daemon (subsequent builds will be faster)

In such case, just change ANDROID_HOME to ANDROID_SDK_ROOT in your ~/.bashrc or similar config file.

Where before was:

export ANDROID_HOME="/{path}/android-sdk-linux"

Now is:

export ANDROID_SDK_ROOT="/{path}/android-sdk-linux"

Don't forget source it: $ . ~/.bashrc after edition.

Igor Parra
  • 10,214
  • 10
  • 69
  • 101
0

Check whether you have added android SDK paths to the environment file (.bash_profile). If you installed android studio with default path, then add the below lines to your environment file. In my case, I am using bash so I have updated the .bash_profile

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

I wasted a day to resolve this issue and finally I got solution -First I removed ionic cordova platform android -Install ionic cordova platform android@8

That's it

0
  1. create a ~/.bash_profile and ~/.zshrc file. touch ~/.bash_profile;
    touch ~/.zshrc;
  2. edit and copy/paste this in your ~/.bash_profile or ~/.zshrc file So, go to your file manager and show all hidden files by using Cmd+Shift+. or Cmd+>

i) Edit your .zshrc file

export LANG=en_US.UTF-8 
export ANDROID_HOME=/Users/bookwarm/Library/Android/sdk
export ANDROID_SDK_ROOT=~/Library/Android/sdk
export ANDROID_AVD_HOME=~/.android/avd
export PATH=$PATH:/Users/{your name}/Library/Android/sdk/tools
export PATH=$PATH:/Users/{your name}/Library/Android/sdk/tools/sdkmanager
export PATH=$PATH:/Users/{your name}/Library/Android/sdk/platform-tools
export PATH=$PATH:/Users/{your name}/Library/Android/sdk/build-tools
export PATH=$PATH:/Users/{your name}/Library/Android/sdk/tools/bin
export ANDROID_NDK=/Users/{your name}/Library/Android/sdk/ndk-bundle
export JAVA_HOME=$(/usr/libexec/java_home)

ii) Edit your .bash_profile file

export ANDROID_HOME=/Users/{your name}/Library/Android/sdk
export ANDROID_SDK_ROOT=~/Library/Android/sdk
export ANDROID_AVD_HOME=~/.android/avd
export PATH=$PATH:/Users/{your name}/Library/Android/sdk/tools
export PATH=$PATH:/Users/{your name}/Library/Android/sdk/tools/sdkmanager
export PATH=$PATH:/Users/{your name}/Library/Android/sdk/platform-tools
export PATH=$PATH:/Users/{your name}/Library/Android/sdk/build-tools
export PATH=$PATH:/Users/{your name}/Library/Android/sdk/tools/bin
export ANDROID_NDK=/Users/{your name}/Library/Android/sdk/ndk-bundle
export JAVA_HOME=$(/usr/libexec/java_home)
  1. 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; Close you terminal and run your command now
Amoo Faruk
  • 63
  • 5
0

On windows I checked the path of the sdkmanager and switched in the terminal to:

cd C:\Android\android-sdk\tools\bin

than I ran following commands:

sdkmanager "platform-tools" "platforms;android-33"

sdkmanager "build-tools;33.0.0"

Before that I checked if Android Studio has installed the tools and if the path is correct, so the version might be different to mine. The build-tools and platform-tools are located in:

C:\Users\[yourUsername]\AppData\Local\Android\Sdk

So you can check your version there.

Jinxi
  • 303
  • 1
  • 13
-1

Go to D:Android sdk\Android SDK and click on SDK Manager and check whether Build Tools are installed or not if they are not installed then install those tools

Roshani
  • 41
  • 5
-1

This is very irritating error and I wasted my almost 9 hours to solve this.

Steps to solve:

Notice ANDROID_HOME while you run ionic cordova build android command. For example in my case it was pointing to some other android sdk which I uninstalled and then it started pointing to right sdk. In my case I uninstalled:

brew cask uninstall android-sdk
brew cask uninstall android-platform-tool

then I ran ionic cordova build android

> cordova build android
ANDROID_HOME=/Users/anand/Library/Android/sdk
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_172.jdk/Contents/Home

Then it might say "licences not accepted" then run below command:

cd /Users/Android/sdk/tools/bin/ then run ./sdkmanager --licenses and accept all with y option

Then it might say unable to download jars. Then go to platform android and build.gradle and search for buildscript, and inside that reverse the order

repositories {
    jcenter()
    maven {
        url "https://maven.google.com"
    }
}
Aniruddh Parihar
  • 3,072
  • 3
  • 21
  • 39
Anand_5050
  • 1,019
  • 2
  • 10
  • 23