Learn how to change the version code of your apk manually in a cordova project.

If you're reading this article and you don't have this problem, then you may be asking to yourself, why should i care about the version code of my application? shouldn't be that automatically handled by Cordova? Certainly you have reason, however that's the problem, it's being automatically handled and that will generate problems while you try to upload a new APK in Google Play (generally it shouldn't generate problems unless you update your android platform from a very old version).

The last week i was working with an old Cordova project, this project was in the version 1.3.3, at least that was the value of the version attribute of the widget tag in the config.xml file of the project (identificated with version code 103038). I decided to update the Android Platform to the latest version using cordova platform update android. Once i made the changes, i simply increased the version to 1.3.4 (just the bug fix release number was increased), then i built the application and tried to published into Google Play. For my surprise i faced the following problem:

Your APK's version code needs to be higher than [version].

This number is an internal version number that is used only to determine whether one version is more recent than another, with higher numbers indicating more recent versions. This is not the version number shown to users; that number is set by the versionName attribute. The value must be set as an integer, such as "50" or "500". You can define it however you want, as long as each successive version has a higher number.

That didn't have sense at all because i increased the version and cordova should do it automatically for me. Then i used aapt (Android Asset Packaging Tool) to dump the information about my APK. This tool is part of the SDK (and build system) and allows you to view, create, and update Zip-compatible archives (zip, jar, apk). It can also compile resources into binary assets.

To dump the information i used:

aapt dump badging MyReleasedFile.apk

Once i reviewed the information, indeed the version of the app was higher, but not the version code of the app. The APK that i uploaded was 10304, that of course is less than 103038.

Apparently this error was caused due to the new android platform whose automatically versioning system doesn't work as it did in previous versions. To solve it, i just needed to change the version code manually.

Change the version code in the Manifest

To change the version code of your apk in Cordova, you need to provide a new attribute in the widget tag of your config.xml file. The android-versionCode attribute will override the default version code generated by cordova and will fix the error in the Play Store in case you have it too:

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.mycompany.myappname" 



Now 103040 is higher than 103038, Happy coding !

Senior Software Engineer at Software Medico. Interested in programming since he was 14 years old, Carlos is a self-taught programmer and founder and author of most of the articles at Our Code World.