cordova-android: Bug: Cordova does not set the minSdkVersion and targetSdkVersion from config.xml correctly in the APK.

How to set the Requires Android version in Play Store? It is always 4.4 for all Ionic / Cordova Android Apps. (See Play Store app details)

Screenshot

The preference android-minSdkVersion in config.xml is set to 22 (Android 5.1). Also android-targetSdkVersion has no effect. And I found nothing in the developer section of Play Store.

Google Play Console says API-Levels: 19+. I think it comes from the apk. But how to set it? minSdkVersion does not work.

Cordova Android is not respecting the config.xml sdk version properties, right? API-Levels == android-minSdkVersion

Ionic Info:

Ionic:
   ionic (Ionic CLI)  : 4.2.1
   Ionic Framework    : ionic-angular 3.9.2
   @ionic/app-scripts : 3.1.11

Cordova:
   cordova (Cordova CLI) : 8.1.1 (cordova-lib@8.1.0)
   Cordova Platforms     : android 7.1.4

System:
   Android SDK Tools : 26.1.1 (C:\Users\%USERNAME%\AppData\Local\Android\Sdk)
   NodeJS            : v8.12.0 (C:\Program Files\nodejs\node.exe)
   npm               : 6.4.1
   OS                : Windows 10

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 21 (2 by maintainers)

Most upvoted comments

I can confirm this bug: the minSdkVersion is ignored from the config.xml (I specify minSdkVersion=21 and the output apk targets 19 which is android 4.4). None of my Cordova plugin sets this minsdkversion to 19 so there is an issue with cordova-android itself.

As a workaround I’ve created a build-extras.gradle with the following content:

allprojects { project.ext { defaultMinSdkVersion=21 } }

I copy this file in the platforms/android folder with a before_build hook and it does the job.

I hope it can help until this issue is addressed.

in your AndroidManifest.xml you can specify it like <uses-sdk android:minSdkVersion="22" android:targetSdkVersion="23" />

Also can set in config.xml

<platform name="android">

  <preference name="android-minSdkVersion" value="22"/> 
  <preference name="android-targetSdkVersion" value="23"/>

  <!--other line code -->

</platform>

upgrading cordova-android to from 7.1.4 (where this bug got introduced I think) to 8.0.0 also solves this problem, due to this fix probably: https://github.com/apache/cordova-android/commit/96975504885a8cf98e251c37b64921337f32c194#diff-c162d66bb4a22683316f0fc47e104078R25

After changing to config.xml to <engine name="android" spec="^8.0.0" /> and package.json to "cordova-android": "^8.0.0",, I had to remove package-lock.json and node_modules for the version not to revert.

From Android Studio, go to “File” >> “Project Structure”.

In “Project Structure” select “app” into the “Modules”, then “Flavors” tab and set “Min SDK Version”

I hope to be helpful

I solved changing lines in file: platforms/android/gradle.properties

org.gradle.daemon=true
org.gradle.jvmargs=-Xmx2048m
android.useDeprecatedNdk=true
cdvMinSdkVersion=21

to

org.gradle.daemon=true
org.gradle.jvmargs=-Xmx2048m
android.useDeprecatedNdk=true
cdvMinSdkVersion=19

thanks @b4zz4 for cite the file

This is the Android Studio solution for a native app. Thanks. But not my problem. It’s about the compiled App (apk) from Cordova. There is a file config.xml with the property android-minSdkVersion. This should do this job. But the Cordova compiler does not respect this configuration.

You mean I have to load the Android project from platforms/android into the Android Studio and set the properties? But I don’t want to modificate (“hack”) the Cordova sources (platform). This should be a non tracked resource (gitignore). Cordova have this setting for “Min SDK Version”, but it does not work. I think this is a bug.

I could set the minSdkVersion in the file AndroidManifest.xml.

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

Not tested, but I’ll try it as workaround. btw. there are several AndroidManifest.xml files. I don’t know which file is the correct file. If I change a file I get erros like:

Manifest merger failed : uses-sdk:minSdkVersion 19 cannot be smaller than version 22 declared in library [:CordovaLib] %PROJECT%\platforms\android\CordovaLib\build\intermediates\manifests\full\debug\AndroidManifest.xml as the library might be using APIs not available in 19
  Suggestion: use a compatible library with a minSdk of at most 19,
    or increase this project's minSdk version to at least 22,
    or use tools:overrideLibrary="org.apache.cordova" to force usage (may lead to runtime failures)

Ok, maybe this is not the correct file. But funny, because I set min: 22 and target: 23. I’ll continue by successive approximation. … Anyway this feature has to be work from Cordova config.xml!

NOTE You have to clean the platform. Otherwise the minSdkVersion has a memory-effect. The value will not be updated. Clean e.g. by removing the android platform folder before build.

Also note that Android does not handle the minSdkVersion value correctly if you try to install the apk manually (copy apk to device and install by file manager). You’ll get a parsing error like “There was a problem parsing the package”. That’s confusing. I expected a message like “This app is not compatible for your Android version.” … But it looks like this is a file manager issue. If I try to install this app by adb install I get a correct message like “Requires newer sdk version $minSdkVersion (currently version is $installedVersion)”. I can’t say how it behaves on Play Store yet. I’ll test it on the next update of the app.

@EmeryGuillaume Thanks for the hint. It’s a great workaround. The build.gradle file contains the default values which I can overwrite before build. That looks promising.