ionic build Android | error: No installed build tools found. Please install the Android build tools

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


Solution 1:

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.

Solution 2:

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

Adding to bash process for different systems

Solution 3:

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

Solution 4:

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

PATH IS SAME FOR UBUNTU(.bashrc) AND MAC(.bash_profile)

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

Solution 5:

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