2

I am having trouble building my ionic application on android on Ubuntu 16.04

This is step step what I have done in order to make it happen

  1. Downloaded Android Studio
  2. Downloaded the Android Sdk
  3. in /.bashrc and /.bash_profile

    export ANDROID_HOME=$HOME/Android/Sdk

    export PATH=$PATH:$ANDROID_HOME/tools

    export PATH=$PATH:$ANDROID_HOME/platform-tools

When I hit sudo ionic cordova build android I a getting this error:

FAILURE: Build failed with an exception.

  • Where:

Script '/home/iraklis/Desktop/mus/platforms/android/CordovaLib/cordova.gradle' line: 68

  • What went wrong:

A problem occurred evaluating project ':CordovaLib'.

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

this here is my ionic info:

Ionic:

   ionic (Ionic CLI)             : 4.6.0 (/usr/local/lib/node_modules/ionic)
   Ionic Framework               : @ionic/angular 4.0.0-rc.3
   @angular-devkit/build-angular : 0.12.2
   @angular-devkit/schematics    : 7.1.4
   @angular/cli                  : 7.1.4
   @ionic/angular-toolkit        : 1.2.2

Cordova:

   cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1)
   Cordova Platforms     : android 7.1.4
   Cordova Plugins       : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 2.3.2, (and 9 other plugins)

System:

   Android SDK Tools : 26.1.1 (/home/iraklis/Android/Sdk)
   NodeJS            : v10.11.0 (/usr/local/bin/node)
   npm               : 6.4.1
   OS                : Linux 4.15

I am thinking that.. maybe this here in cordova.gradle

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

for some reason cannot find the build-tools..?

EDIT

I just noticed, when i do echo $ANDROID_HOME it prints /home/iraklis/Android/Sdk as expected but when i run ionic cordova build android after building it prints ANDROID_HOME=/usr/lib/android-sdk . How can i change that?

Iraklis Bekiaris
  • 1,163
  • 15
  • 43

3 Answers3

0

you need to install the build-tools 25.0.3 (just assuming it may require these):

sdkmanager packages "build-tools;25.0.3"

or even several build-tools versions ...

sdkmanager packages "build-tools;25.0.3" "build-tools;26.0.3" "build-tools;27.0.3" "build-tools;28.0.3"
Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • Doesn't work :(( nor with 19.1.0, 25.0.3, 26.0.3, 28.0.3.. Do you think that for some reason the cordova.gradle file cannot find the build-tools..? – Iraklis Bekiaris Jan 30 '19 at 19:02
  • @IraklisBekiaris I think that they are simply not installed... while "doesn't work" is not an error description. using the SDK Manager GUI in Android Studio would be the other option to install them. – Martin Zeitler Jan 30 '19 at 19:04
  • sorry about that.. how are they not installed since i have download the android sdk and i have exported the paths? Is there something else that needs to be done? Thank you for your efforts – Iraklis Bekiaris Jan 30 '19 at 19:08
  • I just noticed, when i do echo $ANDROID_HOME it prints /home/iraklis/Android/Sdk as expected but when i run ionic cordova build android after building it prints ANDROID_HOME=/usr/lib/android-sdk . How can i change that? – Iraklis Bekiaris Jan 30 '19 at 19:14
  • @IraklisBekiaris that's where `sudo apt-get install android-sdk` would install it. does `which android` return something and can you run it? this would be the standalone GUI for the SDK manager. – Martin Zeitler Jan 30 '19 at 23:19
0

If you have brew installed, you may be able to just try this: brew install android-sdk This should then let you run sdkmanager packages "build-tools;25.0.3"

vr_driver
  • 1,867
  • 28
  • 39
0

The proper command to install the appropriate build tools is

sdkmanager "build-tools;33.0.2"

(Of course substitute whatever version you want for 33.0.2)

Using sdkmanager packages "build-tools;33.0.2" now in 2023 gives a package 'packages' not found error.

Then, add the following to your path to your .zshrc or .bashrc file (or whatever rc file your shell uses

#Add Android Studio SDK to the Environment Variables
export ANDROID_SDK_ROOT="/Users/<your user folder>/Library/Android/sdk"
#ANDROID_HOME is deprecated. Do not use it anymore

#Add Android build-tools and platform-tools to the path
export PATH="$PATH:$ANDROID_SDK_ROOT/tools:$ANDROID_SDK_ROOT/build-tools/33.0.2:$ANDROID_SDK_ROOT/platform-tools"

(Again, be sure to substitute whatever version you're using for the 33.0.2 above. And obviously should be replaced with your actual user-folder name.)