Piero
Piero

Reputation: 9273

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

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

Upvotes: 41

Views: 62064

Answers (9)

Harsh Wardhan Gupta
Harsh Wardhan Gupta

Reputation: 393

In My case I resolved this issue by giving proper permission to android executable file.

I was running android build from Jenkins. So when I downloaded android SDK, in /usr/local/android-sdk/tools/ I saw android executable file. the permission of this file is root because in Jenkins server(ubuntu server) I installed android-sdk as a root user.

When I was running the job I was getting an error as "Android SDK not found. Make sure that it is installed. If it is not at the default location, set the ANDROID_HOME environment variable."

But ANDROID_HOME is having correct path set as well as Android-SDK is also present. Then I check the permission so below are the things I have done and given permission to the whole tools folder.

  1. cd /usr/local/android-sdk/tools
  2. ls -lt (when you run this command you will see android permission as root:root)
  3. chown jenkins:jenkins android
  4. or else you can give jenkins:jenkins permission to all the files present in the tools folder by coming at location "/usr/local/android-sdk" and then run the command "chown jenkins:jenkins -R tools/".
  5. I am running as a jenkins user but if you are running the build as some other user then use that username.

Upvotes: 0

Jon
Jon

Reputation: 6541

Update to new Android package to solve the error -

cordova platform remove android
cordova platform add android
cordova build android --release

Upvotes: 2

waldou
waldou

Reputation: 31

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.

Upvotes: 2

user6358125
user6358125

Reputation:

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!

Upvotes: 22

RAJESH KUMAR ARUMUGAM
RAJESH KUMAR ARUMUGAM

Reputation: 1570

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 :)

Upvotes: 0

Benoît
Benoît

Reputation: 15010

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 [email protected] release.

UPDATE: There were several related subsequent patches done and the newest version is [email protected]. Run cordova platform rm android; cordova platform add [email protected] to fix the issues.

Upvotes: 47

Uahmed
Uahmed

Reputation: 1845

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

Upvotes: 31

Anton
Anton

Reputation: 111

@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

Upvotes: 3

Piero
Piero

Reputation: 9273

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

Upvotes: 0

Related Questions