42

This is a phonegap 3.5 / cordova 3 android app. In www/config.xml I have:

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

However, when I build it, it creates an AndroidManifest.xml with:

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

The result is that people with SDK versions below 19 can install my app from the store. Where is it getting that 10 from and how can I change it? Due to weirdness with Viewport, my app's behavior is suspect on OSes below 4.4 and I am already getting 1-star reviews from 4.2.2 users.

DevOfZot
  • 1,362
  • 1
  • 13
  • 26

6 Answers6

68

With older version of cordova CLI, I used to modify manually AndroidManifest.xml to change a few settings (launch mode, minsdk...) like you do in your answer.

And with Cordova 3.5.something things started to go wrong, and some changes were lost each time I built the project.

Now I added those lines in config.xml and the settings are updated automatically :

<platform name="android">
    <preference name="AndroidLaunchMode" value="singleTop"/>
    <preference name="android-minSdkVersion" value="14" />
    <icon src="res/android/xhdpi.png" />
    <icon src="res/android/ldpi.png" density="ldpi" />
    <icon src="res/android/mdpi.png" density="mdpi" />
    <icon src="res/android/hdpi.png" density="hdpi" />
    <icon src="res/android/xhdpi.png" density="xhdpi" />
</platform>

The advantage is that I can now delete the android platform and recreate it without loosing any setting.

As Phonegap is being updated to be inline with cordova, preferences in config.xml should work with the new version, and maybe you will see your manual updated be lost like it happened to me...

shybovycha
  • 11,556
  • 6
  • 52
  • 82
QuickFix
  • 11,661
  • 2
  • 38
  • 50
  • Starting over with the latest Cordova addressed this issue for me. – DevOfZot Dec 02 '14 at 20:38
  • 1
    This doesnt seem to work for me... I added `android-minSdkVersion , android-maxSdkVersion, android-targetSdkVersion` with value = 22 in all of them... But when I do `add platform` it installs for android target 26. Nonetheless in the AndroidManifest and in config.xml, EVERYTHING is set to 22. Therefore,when I do `run android --device`, instaed of working with SDK 22, it goes and downloads SDK 26 and kindat forcing me to install with it...I'm using Ionic 2 – Jason Krs Apr 08 '18 at 22:01
  • each version of android platform has a target sdk associated with it and I don't think you can change it. And version 7 of the android platform is no more compatible with android versions older than kit kat, so maybe you can't have a min sdk lower than that. To have a lower target sdk you have to install an older version of cordova android platform, for example `cordova platform add android@6.2.3` is what I use with android-minSdkVersion=16 to have my app work with all devices starting from jelly bean. – QuickFix Apr 09 '18 at 11:28
  • not sure why you want to force a target sdk 22 but to do so you should use version 5.1.1 or something around that. You can have a look at this page to have an idea : https://cordova.apache.org/docs/en/latest/guide/platforms/android/index.html – QuickFix Apr 09 '18 at 11:43
45

STEP 1) yourapp/config.xml file <platform name="android"> tags add two preference

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

STEP 2) cordova platform rm android run cmd code

STEP 3) cordova platform add android run cmd code Check your AndroidManifest.xml file if look like below

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

every thing is OKAY :)

Ferhat KOÇER
  • 3,890
  • 1
  • 26
  • 26
  • 3
    I've used cordova 7.1 and no need for steps 2 + 3. (AndroidManifest.xml was updated after build) – jony89 Feb 06 '18 at 18:43
  • For "cordova-android" version 8, after step 3, check the values of "cdvMinSdkVersion" and "cdvTargetSdkVersion" in "platforms/android/gradle.properties" – vivanov Dec 10 '19 at 11:47
  • And do not forget to run cordova plugin save before cordova platform rm android. – Iwan Ross Aug 15 '20 at 13:35
24

Edit and improved answer:

To answer this, it's better to begin with Build version, or API Level. API Level is an integer value that uniquely identifies the framework API revision offered by a version of the Android platform.

API Level 8 == android Platform 2.3(ginger bread)
API Level 17 == android Platform 4.2(jelly bean)

To see complete comparison of APILevel and its AndroidPlatform check here


targetSdk is to be used by phonegap only. This tell phonegap to use certain APILevel to build this app. This does not meant to limit any user from downloading your app. It is more like to say, "The app is optimized for this APILevel". example

 <preference name="android-targetSdkVersion" value="17"/> //android 4.2

This app is build(optimised) using APILevel 17 (which is jellyBean or androidPlatform4.2)


minSdk on the other hand, limit the user/device. minSdk is the minimum requirement of Sdk for user/device. Any device with APIlevel less than APILevel used by minSdk, won't be able to download this app. example:

 <preference name="android-minSdkVersion" value="11"/> //android 3.0

to download this app, the device has to at least run on android 3.0 (APILevel 11)


Finally, when used together:

<preference name="android-minSdkVersion" value="11"/> //android 3.0

 <preference name="android-targetSdkVersion" value="17"/> //android 4.2

This statement means that this app is optimized for android4.2, with minimum requirement of android 3.0


Doc: http://docs.build.phonegap.com/en_US/configuring_preferences.md.html#Preferences

vdj4y
  • 2,649
  • 2
  • 21
  • 31
3

For anyone getting here looking for a way to set a specific target version, I found this: I just had the same problem. I had to change the target:

Project target.

target=android-22 This should be done in two files:

myApp/platforms/android/project.properties myApp/platforms/android/CordovaLib/project.properties

Also the manifest should be updated:

From Sebastian answer placed here: Cordova : [Error: Please install Android target: "android-21"

Community
  • 1
  • 1
Leo Medeiros
  • 154
  • 1
  • 3
0

I was able to fix this by manually editing platforms/android/AndroidManifest.xml:

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

The Phonegap documentation seems to imply that this file should inherit the value of the android-minSdkVersion preference, but it must be changed manually. The android-minSdkVersion preference doesn't seem to do anything as far as I can tell.

DevOfZot
  • 1,362
  • 1
  • 13
  • 26
  • targetSdk is like reccomended-sdk(it doesnot enforce or limit), minSdk is the minimum requirement of Sdk. yes you need to change the min-sdk since you want minimum requirement Sdk – vdj4y Nov 25 '14 at 22:24
  • 3
    On second thought, I recommend not going this route - manually editing platforms/android/AndroidManifest.xml caused that Manifest to be out of sync with the other various copies of AndroidManifest.xml that get strewn around the platforms/android subdirs, which led to other issues that caused me to nuke and repave. – DevOfZot Dec 02 '14 at 20:38
0

I fixed this issue by building with Android Studio instead of using Cordova CLI to build.

Post Impatica
  • 14,999
  • 9
  • 67
  • 78