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)
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)
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
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
to
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 propertyandroid-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 fileAndroidManifest.xml
.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:
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.