cordova – Phonegap always asks me to install android sdk 19 but i have already installed it-ThrowExceptions

Exception or error:

This is what exactly i do :

$ phonegap create myapp
$ cd myapp
$ phonegap run android

but it fails.

I have checked everything.
my environments are ok, installed the latest version.
when i type

$ android

on my CMD it shows me that every latest updates are already installed but can not make it work :

$ phonegap run android

it returns :

                         ^
Error: Please install Android target 19 (the Android newest SDK). Make sure you
have the latest Android tools installed as well. Run "android" from your command
-line to install/update any missing SDKs or tools.
    at C:\Users\yeayea\.cordova\lib\android\cordova\3.3.0\bin\lib\check_reqs.js:
80:29

please help otherwise i will hang myself! 🙁

How to solve:

I had the same problem and I thought I had API 19 installed but I didn’t.

In CMD type “android”

Scroll down to Android 4.2.2 (API 19)

Check all and install them.

Even if you already have API 20 installed and all the other packages and tools installed, you need this.

###

When you run phonegap create myApp, there is a script which checks that you have a specific android platform version. The platform it is looking for is in the file (for OS X): /Users/username/.cordova/lib/android/cordova/3.5.0/framework/project.properties
and for Cordova 3.5.0 has the line:
target=android-19

Cordova and PhoneGap are the same in this regard so any reference to cordova also applies to phonegap.

To check that you have this target run:
android list targets and you should have an entry like:

Available Android targets:

id: 1 or "android-19"
Name: Android 4.4.2
Type: Platform
API level: 19
Revision: 3
Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, WXGA720, WXGA800, WXGA800-7in
Tag/ABIs : default/armeabi-v7a

By default only the latest target is installed which is currently android-20.

You have two options:

  1. Install the target that matches what is in the project.properties file. This would seem to be the best approach as this would be the target cordova was tested against.
  2. Edit the project.properties file to match a target on you have installed. This should get you past this problem but could have unexpected impacts.

To install an additional target, as Curtis said, run the Android SDK Manager (android) and select the Android target you require. Note these appear below the Tools folder which also has a number of different versions, but installing a different version of the tools will not solve this problem.

You can also see the targets you have installed in the platforms directory of the Android sdk.

###

I was able to solve this problem by checking if the environment variables were detected in the current working directory or not.
The directory where I was running phonegap run android wasn’t able to detect the andorid environment variable so I copied it to another directory c:/users//<> and tried again it worked.

It might happen if your sdk is not installed in c: drive (Primary Partition)

###

For Windows, in the Environment Variable try place the java\bin directory before the windows\system32 directory.

This makes the SDK Manager to use java from java\bin directory else it would use java found in the system32 folder.

This should help!

###

regarding switching cordova to installed version – I found it under C:\Users[username].cordova\lib\npm_cache\cordova-android\3.6.4\package\framework\project.properties.
After changing to target 21, “cordova platform add android” worked . Thanks for the thread – helpful.

Leave a Reply

Your email address will not be published. Required fields are marked *