14

While experienced with phonegap and xcode, I'm new to android. I have installed phonegap 3.0 ...

npm install phonegap
phonegap --version
3.0.0-0.14.3

I've installed adt-bundle-mac-x86_64-20130729. The command line tools (eg: android) seem to work fine. When I try to add android as a platform ..

phonegap local build android

I get ...

[error] Please install Android target 17 (the Android 4.2 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.

I see similar questions still unanswered ... Phonegap 3.0 CLI issue android target number in build app

When I do install android-17 it works fine, which is cool, but I need to use android-18 so I can use BLE.

I see that Fil Maj apparently fixed this issue on Jul 31 ... https://git-wip-us.apache.org/repos/asf?p=cordova-android.git;a=commitdiff;h=c2c5f710

.. but I don't appear to have that fix in the version of phonegap I downloaded. I thought perhaps it was only in cordova, so I installed that too, but ran into the same issue.

I tried hacking the four js files in the npm directories that contain the check directly, but that didn't take (ie: the error persisted).

Can anyone please suggest either ...

1) how to download a version of phonegap/cordova with the problem fixed, or

2) how to tell phonegap/cordova which version of android I'd like to target

Thanks so much ...

Community
  • 1
  • 1
user2776896
  • 141
  • 1
  • 1
  • 4

11 Answers11

11

Find file android_parser.js in Windows it is undr path:

C:\Users\USER_NAME\AppData\Roaming\npm\node_modules\cordova\src\metadata

change in file android_parse.js

OR if You are makking application from PhoneGap not Cordova:

C:\Users\USER_NAME\AppData\Roaming\npm\node_modules\phonegap\node_modules\cordova\src\metadata\android_parser.js

go to line: 57

if (output.indexOf('android-17') == -1) {

and change it for:

if (output.indexOf('android') == -1) {

This will let You not to wory about future :)

But then You can occur this Error

[Error: An error occured during creation of android sub-project.
]

To fix it You will have to goto this path:

C:\Users\USER_NAME\.cordova\lib\android\cordova\3.1.0\framework\project.properties

And change this line:

target=android-17

To this:

target=android-19

Or whatever is Your Android SDK version

What to do if You want to use Android 2.2 ?

Just simple go to:

Your_Project_Folder/platforms/android/AndroidManifest.xml

And change:

<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />

To:

<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="19" />

And after that import Your project to Your IDE

Enjoy :)

AtanuCSE
  • 8,290
  • 13
  • 67
  • 103
bumerang
  • 1,636
  • 19
  • 29
  • 5
    Editing the AndroidManifest.xml directly is not a good practice when developing Cordova apps. Anyone knows how to configure `minSdkVersion` and `targetVersion` from the "JavaScript side"? – sgimeno Jan 30 '14 at 12:25
  • They can be set within config.xml and I'm experimenting with this at present, in PhoneGap Build. – Magnus Smith Feb 27 '14 at 13:38
  • @Magnus Smith As I remember (can be wrong it was a while ago), in version 17 it was hard coded, and there was no usage of settings variable. So please check this file first before You 'kill' Your computer ;) – bumerang Feb 28 '14 at 07:05
6

If anyone gets here using cordova and/or chrome mobile app toolchain. I edited platforms/android/project.properties directly to target=android-19 and it built.

cheers

Harry Moreno
  • 7,937
  • 3
  • 49
  • 89
2

Simply open your AndroidManifest.xml file and set minimun and targeted version. In your case 18. Same answer to question Phonegap 3.0 CLI issue android target number in build app.enter image description here AndroidManifest.xml file is located in: YOURPROJECT\platforms\android. If you need more assistance ask, will try to help you. Post your AndroidManifest.xml file so I can check.

Community
  • 1
  • 1
divoto
  • 279
  • 1
  • 11
  • I am getting the same error with a simple HelloWorld app but there are no files in the folder you specify and multiple AndroidManifest.xml files on my pc in various locations. Any idea which one (the mmaster) I should change? – RedEyedMonster Oct 02 '13 at 10:01
  • Do you have android directory in Yourprojectdir\platforms. If YES it is inside that directory. If you don't have it you actually missed 1 step in creating the app. You have to search it in your Phonegap application directory not in Android SDK. – divoto Oct 02 '13 at 17:36
  • True, this is how you would change the target SDK for a cordova/phonegap app, but this is not the OP's question. – MBillau Oct 04 '13 at 19:02
  • 1
    When you create a phonegap application the platforms directory stays empty until you start adding platforms to it, no? That seems to be my experience anyways. Since invoking the command: "phonegap build android" fails no android artifacts are created in the first place so I don't see how your solution would work (I'm having the same problem as OP) – IcedDante Oct 14 '13 at 00:47
2

Go to \cordova\src\metadata\android_parser.js in function check_requirements and change the lines 56,57,66 from 17 to 18. It will then be ok.

Dionysios Arvanitis
  • 1,005
  • 9
  • 10
2

Make sure you have the latest version:

  • PhoneGap: sudo npm update -g phonegap
  • Android SDK: depending on how you installed it, if you did it through brew: brew update android-sdk

Then run aandroid, and download the latest API.

Then PhoneGap will use the latest API by default when running phonegap build android.

If you need to update a current project, run inside the project folder:

phonegap platform update android

And now if you run build again, it should use the latest version.

Jesús Carrera
  • 10,611
  • 4
  • 59
  • 55
2

I had installed cordova through npm, therefore to make it work I modified target in ~/.cordova/lib/npm_cache/cordova-android/3.6.3/package/framework/project.properties

wieczorek1990
  • 5,224
  • 1
  • 22
  • 17
1

I think you have the wrong version of Phonegap, mine says 0.3.0-0.15.0. I think Fil's fix would definitely have made it into the final build, so I think you must be doing something goofy when installing Phonegap. This is what I did:

npm install cordova -g (or I guess in your case it would be Phonegap and not cordova.) This will install cordova (or phonegap) globally so that you can access it anywhere with the 'cordova' command. If you already have it installed try npm update instead of npm install.

Navigate to a workspace location, like C:\workspace.

Type cordova create MyApp which will create a Cordova project at C:\workspace\MyApp. The workspace will have the following folders:

/www/ - where you place all of your HTML and JavaScript

/platforms/ - this will have folders for android, ios, and any other platforms you add. Your stuff from /www/ will get copied over here in the right place for each platform. This is where you would edit platform-specific files, for example, to change the target-sdk, you want to edit /platforms/android/AndroidManifest.xml.

/plugins/ - this is where all of the plugin code will go when you do cordova plugin add {link}. I can't think of any reason why you should ever edit anything in this folder (but there probably are some good ones.)

/merges/ - any files here will get merged with the corresponding files in /www/ and pushed into /platforms/, see the documentation.

After running the create command, you need to add the platforms:

cd MyApp

cordova platform add android -d - the -d gives us debug info

cordova build android - this will build the android app and you will see stuff from /www/ copied over to /platforms/android/assets/www.

One If you are still having issues, did you try what it says in the output, that is, running android from the command line? This will bring up the "Android SDK Manager", make sure that you have the latest version of the SDK installed as well as the latest Android SDK Tools and Android SDK Platform-tools (mine are 22.0.5 and 18.0.1, respectively.)

There may also be issues if you have never created an Android emulator object (use the AVD manager) although that sounds less likely.

MBillau
  • 5,336
  • 2
  • 25
  • 29
1

C:\Users\USER_NAME.cordova\lib\android\cordova\3.1.0\framework\

should be in bumerang's anser

C:\Users\USER_NAME.cordova\lib\android\cordova\3.1.0\framework\project.properties

Manish B
  • 21
  • 3
1

PhoneGap Build now supports an option to set the Android SDK version. It is documented here but basically what you need in config.xml is:

  <preference name="android-targetSdkVersion" value="18" />

It will then set the property correctly in AndroidManifest.xml.

Note: This supposedly only works for PhoneGap build, but I am using the Ionic command line tools (on Cordova 5.1.1) and it appears to work fine for me too.

Chris Rae
  • 5,457
  • 2
  • 31
  • 48
0

reading from the release notes of version 3.1.0, it says:

  • Incremeting version check for Android 4.3 API Level 18
  • Upgrading project to Android 4.3

Therefore, upgrading to Phonegap 3.1.0 should do the trick.

Mobiletainment
  • 18,477
  • 9
  • 70
  • 90
  • now there is `Android 4.4 API Level 19` so it won't help I have experienced this @Dionysios have the best answer includding my comment :) – bumerang Nov 08 '13 at 12:25
0

You are in the wrong place guys

YOU SHOULD TRY THIS: phonegap local build android

this will add the android to your platforms folder...

Mahmoud Zalt
  • 24,048
  • 7
  • 74
  • 78