TheBearF8
TheBearF8

Reputation: 395

How to compile Cordova Apps for older Android versions

I have installed cordova-android version 7.0.0

My app must run in Android 4.1.1

So I added the platform with:

cordova platform add [email protected]

Then I get:

Using cordova-fetch for [email protected] Adding android project... Unable to load PlatformApi from platform. Error: Unhandled "error" event. (Does not appear to implement platform Api.) Error: Package name must look like: com.company.Name

Any advice?

Upvotes: 8

Views: 13797

Answers (6)

Ryan Taylor
Ryan Taylor

Reputation: 13415

This is full of bad answers.

This page shows the versions of cordova-android and their compatible Android SDK APIs. If you want to support Jelly Bean you need to use cordova-android version 6.x.x – The latest versions (7.x.x) only support down to API level 19 (v4.4 called Kit Kat). There's no reason to do any of this other crazy stuff!

Just run cordova platform remove android && cordova platform add android@6

Make sure your cordova updated too with npm i -g cordova, it works fine without downgrading. Also keep in mind you no longer need the cordova-plugin-compat package!

Also note that you need to download a different SDK API than 16, but it will still work on older devices, like Android 4.1.1.

Upvotes: 0

jcesarmobile
jcesarmobile

Reputation: 53301

The original question has been edited and it ask for Android 4.1.1 (SDK 16) support now and not SDK 19 as the original answer.

To support Android 4.1.1 you can use cordova-android 7.0.0 or older, cordova-android 7.1.0 increased the Min SDK to 19.

ORIGINAL ANSWER:

First of all, even latest cordova-android version (7.1.0 at the moment), still supports SDK 19 and newer, so not sure why do you want to downgrade to 4.1.1.

Now, to get cordova-android 4.1.1 working you need an old Cordova CLI, because new CLIs require new platforms and are not compatible with very old one such as 4.1.1.

So install Cordova CLI 5.4.1 with

npm install -g [email protected]

After doing that, you should be able to add cordova-android 4.1.1 with

cordova platform add [email protected]

Upvotes: 10

Zubli Quzaini
Zubli Quzaini

Reputation: 352

Add crosswalk to your project can support Android version 4.1.1

Firstly, ionic cordova platform remove android

Then, ionic cordova platform add [email protected]

Finally,

cordova plugin add cordova-plugin-crosswalk-webview

Upvotes: 1

QuickFix
QuickFix

Reputation: 11721

Cordova android platform version is not the same as the android version your phone needs to be runing.

A version of cordova platform supports a range of android OS versions. You can find an array of supported Android versions for each cordova android platform version on the Codova Android platform guide page.

Cordova android platform versions 6.x supported android versions from 4.1 to 7.1.

For cordova android platform version 7.x the minimum version has been set to 4.4 so platform version 7.x can't be used if you need to support phones older than Kit-Kat (the minimum sdk was changed).

All that to say that what you need is a version 6 of cordova platform tools not 4.1.1, so with the following line, it should work fine with :

cordova platform add [email protected]

I haven't tested latest version of the CLI, for the moment I'm still using cordova version 7.0.1 with android platform 6.2.3, so I'm not sure if cordova android 6.4.0 will work with cordova 8 or if you will have to downgrade also the CLI version.

Upvotes: 8

sirius2013
sirius2013

Reputation: 325

Please update node and cordova as latest one.

npm install -g cordova

and add android 6.2.3 version.

cordova platform add [email protected]

This version will work great now.

Upvotes: 2

Naveen
Naveen

Reputation: 683

Install Andorid platform API level 19 from Android SDK Manager

Install stable cordova:

npm install -g [email protected]

cordova platform add android

Add this inside <widget>...<widget/> in config.xml:

<preference name="android-minSdkVersion" value="19">
<preference name="android-targetSdkVersion" value="19">

Make the below changes in build.gradle:

defaultMinSdkVersion=16
defaultTargetSdkVersion=19 
defaultCompileSdkVersion=19

Make the below change in project.properties:

target=android-19

Run your code:

cordova run android

Upvotes: 3

Related Questions