40

I am having problem to build android with Cordova, when I execute cordova build android, I receive this error:

Error: Android SDK not found. Make sure that it is installed. If it is not at the default location, set the ANDROID_HOME environment variable.

I have do this to fix it:

sudo nano  ~/.bash_profile

and add this line:

export PATH=${PATH}:/Users/myname/Library/Android/sdk/platform-tools:/Users/myname/Library/Android/sdk/tools

then this:

source ~/.bash_profile

but I get again that error when I build, how can I fix it?

UPDATE:

This is the line I Added in the bash:

export PATH=${PATH}:/Users/myname/Library/Android/sdk/platform-tools:/Users/myname/Library/Android/sdk/tools
export ANDROID_HOME=/Users/myname/Library/Android/sdk
Piero
  • 8,533
  • 18
  • 82
  • 153

8 Answers8

46

The recent Android SDK tools removed the android command.

$ android -v
The android command is no longer available.
For manual SDK and AVD management, please use Android Studio.
For command-line tools, use tools/bin/sdkmanager and tools/bin/avdmanager

cordova is behind the change and someone seems to be working on it: https://issues.apache.org/jira/browse/CB-12554

You can also downgrade your tools to a version where the android was still available.

Nevertheless, I found a way to run the Android app without having to downgrade my SDK tools. I would (1) run cordova prepare, then (2) run the command I need from Android Studio. In my case, running it on the emulator was enough.

UPDATE: The issue CB-12554 is resolved now and was released with the cordova-android@6.2.0 release.

UPDATE: There were several related subsequent patches done and the newest version is cordova-android@6.2.3. Run cordova platform rm android; cordova platform add android@6.2.3 to fix the issues.

jakub.g
  • 30,051
  • 7
  • 78
  • 118
oldergod
  • 14,370
  • 7
  • 54
  • 81
  • Thanks for confirming this. I feel like an idiot but I cannot find where previous SDK versions are kept. Will keep searching of course and report back here if I find anything. Also, will the older SDKs work with the latest release of Android Studio? I have been using Android Studio to prepare our Cordova releases for the app store. – Rjak Mar 23 '17 at 13:52
  • To save others time, I have done a lot of searching and it doesn't appear that previous versions of Android Studio are made available any more. This stable channel (http://tools.android.com/download/studio/stable) is now obsolete. Taking partial paths from the download links listed on the official download page results in 404s (https://developer.android.com/studio/index.html#downloads). I cannot find previous versions of tools hosted anywhere. We might be stuck in a holding pattern for now. – Rjak Mar 23 '17 at 14:28
  • @Rjak I updated my answer but you could probably run `cordova prepare` which would set up all the required files inside `/platforms/android` then run an Android command as if it was a pure Android app. It worked for me. – oldergod Mar 24 '17 at 05:16
  • I am still getting this error. I am on Cordova 6.5.0. I don't think the issue is resolved. – clavio Apr 07 '17 at 18:09
  • 1
    @clavio the version number 6.2 refers to the version of cordova-android platform (you can check your current version by running: cordova platform ls). 6.2.1 was released recently. Check out [Cordova Android 6.2.1 Released!](https://cordova.apache.org/announcements/2017/04/05/android-release.html) for more info and how to update – jetpackpony Apr 11 '17 at 18:44
  • Still not working for me at this date with latest Android SDK and Cordova Android 6.2.1. – adriendenat Apr 22 '17 at 19:17
  • @Grsmto I had no problem with the latest release. – oldergod Apr 23 '17 at 02:41
  • FYI Newest version is 6.2.3 which fixes some other related bugs – jakub.g May 11 '17 at 12:58
  • I thought about something like that. Great advice! – Torsten Barthel Aug 24 '17 at 13:27
  • `cordova platform update android@6.2.2` will solve the issue. I guess cordova team has fixed this. https://stackoverflow.com/questions/42668185/could-not-find-gradle-wrapper-within-android-sdk-might-need-to-update-your-andr – Asqan Nov 08 '17 at 12:27
31

For me this work , first check your cordova android version

cordova platform version android

it shows 5.0 to me and after that upgrade the version by this command

cordova platform update android
Uahmed
  • 1,717
  • 4
  • 27
  • 40
21

TL;DR In some cases, even if you have successfully added android sdk to your path the problem still persists, the reason is related to your Android tools/ folder version, currently the android command is not supported anymore but it is still required by the command ionic cordova build android, then you should download an old one.

Now that you know where the problem is, let's get into the solution:

  1. Download an old sdk tools version according to your platform Mac, Windows, Linux.
  2. Replace the current tools/ folder in /Users/username/Library/Android/sdk on Mac or C:\Users\[account]\AppData\Local\Android\sdk on Windows or ~/Android/Sdk on Linux by the downloaded tools/ folder.
  3. Restart your command-line and be happy!
3

@Rjak here is the manual for downgrading SDK version with valid links for older SDK versions. It works for me with same issue, after downgraded to tools v25.2.5 & platform-tools to v25.0.3 build successful

Community
  • 1
  • 1
Anton
  • 101
  • 1
  • 8
  • Unfortunately I'm not able to get this to work. I am looking at v25.2.5. I found a tools package at http://dl-ssl.google.com/android/repository/tools_r25.2.5-macosx.zip, but there is no corresponding platform tools package at http://dl-ssl.google.com/android/repository/platform-tools_r25.2.5-macosx.zip. – Rjak Mar 29 '17 at 16:35
  • Would be helpful if Google gave directory listings instead of 404s!! :) – Rjak Mar 29 '17 at 16:36
  • 1
    here is the list of available [platform-tools](https://developer.android.com/studio/releases/platform-tools.html). So you've got 404 just because they really don't have it :) try this [one](http://dl-ssl.google.com/android/repository/platform-tools_r25.0.3-macosx.zip) instead. – Anton Mar 30 '17 at 14:47
2

As someone else stated, it is because of the android command being deprecated:

   C:\>android
   **************************************************************************
   The "android" command is deprecated.
   For manual SDK, AVD, and project management, please use Android Studio.
   For command-line tools, use tools\bin\sdkmanager.bat
   and tools\bin\avdmanager.bat
   **************************************************************************

In my case, I managed to fix it changing the newer android.bat that is bundled in the sdk, in the "tools" folder.

Just change this lines in the sdk/tools/android.bat:

From this: (Line ~20)

set avd_objects=;avd;target;device;

To:

set avd_objects=;avd;targets;device;

From This: (Line ~37)

echo android list target

To:

echo android list targets

Explanation: The cordova build.bat will eventually call check_reqs.js script, and thats where this validation is done. If you look for the actual error text, it shows that the script is trying to call "android list targets --compact" command, which I assume was the older way to do it.

Mr Bean
  • 83
  • 1
  • 5
waldou
  • 31
  • 5
2

Update to new Android package to solve the error -

cordova platform remove android
cordova platform add android
cordova build android --release
Jon
  • 6,227
  • 6
  • 35
  • 58
0

I solved my question uninstalling Android Studio and install the CLI SDK Manager following this guide:

https://guides.codepath.com/android/Installing-Android-SDK-Tools

Piero
  • 8,533
  • 18
  • 82
  • 153
0

In My Case, This is a Scenario

1.I have an SDK platforms tools Version 23

2.I have added the Android Platform to My Cordova Project

3.It works fines Until I update the SDK to 26

4.After Updating the SDK it Throws the same Error

Cordova: Android SDK not found. Make sure that it is installed. If it is not at the default location, set the ANDROID_HOME environment variable

  1. I just Resolved this by removing and Adding the Android platforms in my Project

    cordova platform remove android

    cordova platform add android

  2. Now it works fine :)

RAJESH KUMAR ARUMUGAM
  • 1,433
  • 19
  • 32