How To Change versionCode in cordova / Ionic Apps For Android

综合技术 2017-11-15

In this post we will take a look at how you can set versionCode in you cordova / Ionic apps while building for android.

Before we take a look at how to set versionCode, let’s first understand what a versionCode is. versionCode is an integer number which is used to keep track of app versions. The grater the versionCode, the latest version of you app. This versionCode is not show to the user. This is just for internal tracking by the PlayStore. For a more detailed definition take a look at the Android docs here

The gratest value of the versionCode can be 2100000000.

You are required to increment the versionCode of your app every time you push a new update to you app. If you do not increment the versionCode then while uploading your app PlayStore will give you an error saying Your APK's version code needs to be higher than

You can set the versionCode in you config.xml
file using the widget tag as shown below.

Now let me tell you why I needed to write this post. It turns out that there is a bug in the build system of android-gradle which appends 8
to the version code that you have set. For example, you have set your app’s versionCode to 1
, but when you build your app using corova / Ionic the app will have the version code of 18
. As you can see that 8
is being appended. As the maximum number of versionCode can 2100000000, if 8
is appended each time you will be able to update your app only 9 times.

There are other solutions in different forums that tell you to change the andoridManifest.xml
file, some even ask you to change the gradle build file. I would stay away from all of these solutions as they are temporary. This is because andoridManifest.xml
and the gradle file are dynamically added and generated during compile time. Which means that things can change when you run the build command.

How to Solve Cordova / Ionic Appends 8 To versionCode?

Let us now get started with the solution. I will be mentioning the solution for both Corodva and Ionic.

For Cordova

We can use the following build command.

cordova build --release android -- --versionCode=3

Note that we are passing the versionCode
CLI parameter with the value of 3

For Ionic

Ionic nests the cordova command on level deep. So for Ionic we will use the following build command.

ionic cordova build android --release -- -- --versionCode=3

Note the extra --
in the command.

How To Check Cordova / Ionic versionCode?

You can check all the build info of the apk file using the aapt tool. AAPT (Android Asset Packaging Tool) is a tool that is a part of the android SDK build-tools.

You can run the aapt tool with the following command.

aapt dump badging .platformsandroidbuildoutputsapkandroid-release-unsigned.apk

This will give all the info about the apk. The output will look something as follows.

package: name='io.ionic.starter' versionCode='3' versi
onName='3.0.1' platformBuildVersionName='6.0-2704002'
uses-permission: name='android.permission.INTERNET'
application: label='MyApp' icon='res/drawable-mdpi-v4/icon.png'
launchable-activity: name='io.ionic.starter.MainActivi
ty'  label='MyApp' icon=''
feature-group: label=''
  uses-feature: name='android.hardware.touchscreen'
  uses-implied-feature: name='android.hardware.touchscreen' reason='default feature for all apps'
supports-screens: 'small' 'normal' 'large' 'xlarge'
supports-any-density: 'true'
locales: '--_--'
densities: '120' '160' '240' '320' '480' '640'

This way you can check the versionCode of you release apk before uploading it to the PlayStore.


Setting the versionCode for cordova / Ionic has been an issue for quiet some time. Using the CLI parameter solves this. A thing to note is that the CLI parameter will override the value of versionCode set in the config.xml

Leave Me Your Questions And Feedback

Getting your feedback inspires me the most so hit me up in the comments here or on the comments section on my YouTube Channel
or on twitter @pointDeveloper


Android data binding error: Runtime fail... my partner in ours' project use android my pc had error,but in his mac not error.i cant resolve this program.please help!! it's my buil...
Android Kotlin Basics – Auto-mapping Views About This Series This “Andorid Kotlin Basics” blog series is all about fundamentals. We’ll take a look at the basics of building Android apps with...
Best Android Database Libraries for Pro Developers There are several popular ORM database libraries out there (SQLDelight, GreenDAO, SugarORM) but we’re going to see top 10 Android database library and...
Reflecting on our ten year App Engine journey Ten years ago, we announced Google App Engine with a simple video and a blog post . It is truly humbling to look back at the strides we have...
Xposed也要热更新–改 前言 去年很早的时候,就写过一篇关于xposed热更新的demo,其实这次的东西早就想写了,但是一直没(lan)时(de)间(xie),所以拖到现在才开始写。 这次我把Xposed热更新写成了一个库,只需要简单两步,即可完成对xposed不重启更改代码的操作。 库的链接如下: http...