How to get Cordova 3.4.0 to set Android version name/code on build?

Steven Anderson picture Steven Anderson · Apr 11, 2014 · Viewed 19.6k times · Source

I am currently using Cordova 3.4.0 and the CLI to build my project to target android using the command:

cordova build android

OR

cordova build android --release

My config.xml has the following specified:

<widget id="com.example.myapp" 
        version="0.0.3" 
        versionCode="2" 
        ...
        >
</widget>

The resulting AndroidManifest.xml in myapp/platforms/android does not get updated with the version and version code specified in config.xml. It stays as the default:

<manifest 
        android:versionCode="1" 
        android:versionName="1.0"
        ...
</manifest>

Is this a bug? Or is there some other way I should specify the versionCode and versionName for Android in the config.xml? Even maybe, is there a hook I can use to update AndroidManifest.xml with the correct version before build?

I would rather not have to update this manually each time I want it to change as:

  1. It is error prone and fiddly
  2. It wont be an obvious thing to change for unfamiliar developers
  3. None of the platform folders are stored in source control

For these reasons I would like the version numbers to be set in the config.xml. Any ideas?

Thanks

Answer

Diogo picture Diogo · May 21, 2014

At last with Cordova 3.5.0-0.2.4 I added this attribute to the <widget> node config.xml

 android-versionCode="10"

and the AndroidManifest.xml was properly updated to

 android:versionCode="10"