Problems updating Android versionCode attribute using command line tools

1,767 views
Skip to first unread message

Simon Fisher

unread,
Sep 3, 2013, 12:07:29 AM9/3/13
to phon...@googlegroups.com
Hi, I'm new to PhoneGap and I'm testing out the command line tools to see how they might fit in with our existing build & deployment process. Currently I seem to unable to update the 'versionCode' property for Android apps, and I'm not sure what I might be doing wrong.

I am using PhoneGap 3.0.0-0.14.3, running on Windows

Here are the steps I've taken:

1) Create 'Hello World' sample app
phonegap create hello com.example.hello HelloWorld

2) Modify \hello\www\config.xml with updated version numbers
<widget id="com.example.hello" version="1.0.1" versionCode="2" ... >

3) Build the app
cd hello
phonegap build android


When I check the hello\platforms\android\AndroidManifest.xml file, I can see that the 'android:versionName' property is 1.0.1, however the 'android:versionCode' property is set to 1. If I upload the resulting .APK file to TestFlight (or check it with other means) those version numbers match up '1.0.1 (1)' etc.

Am I doing something wrong? Should I be updating the version code somewhere else? Ideally I want to be able to set the version numbers in once place for both iOS and Android versions of my app. Any advice would be appreciated.

Cheers,

Simon

David Paquet Pitts

unread,
Sep 13, 2013, 2:39:21 PM9/13/13
to phon...@googlegroups.com
Can't help, but just wanted to say that I experienced the same problem.

Florian Böhle

unread,
Oct 28, 2013, 5:02:12 PM10/28/13
to phon...@googlegroups.com
Same Problem here. Using PhoneGap 3.1.0-0.15.0 on Mac OS X 10.8 and 10.9.
I also tried using 
<preference name="android-versionCode" value="2" />
but without luck.

Did you come up with a solution so far?

Cheers,

Florian

Mateusz Mucha

unread,
Nov 6, 2013, 5:57:05 AM11/6/13
to phon...@googlegroups.com
I have the same problem and can't find the solution.  This is the sole reason that keeps me from upgrading from some old version (I think it's 2.3).  How do you manage to push your apps to the Play Store without stumbling into "versionCode is smaller than the last version" error?

Florian Böhle

unread,
Nov 18, 2013, 8:09:00 AM11/18/13
to phon...@googlegroups.com
Hey,

my current workaround is to simply increase versionCode inside the AndroidManifest.xml inside "platforms > android" by hand.

Cheers,

James Drucza

unread,
Dec 2, 2013, 10:40:40 PM12/2/13
to phon...@googlegroups.com
Here is another work around using a combo of ruby (rake) and command line commands (bash) which we've added to our build task to automate the setting of the versionCode in the ./platforms/android/AndroidManifest.xml file before calling 'cordova build android':

    android_version_code=`git rev-list HEAD --count`.strip
    android_manifest_file = './cordova_app/platforms/android/AndroidManifest.xml'
    `sed -i.tmp 's|versionCode="[0-9]*"|versionCode="#{android_version_code}"|'  #{android_manifest_file}`
    `rm #{android_manifest_file}.tmp`

Explanation:
Line 1 sets the version_code from the git commit count but you could replace this with whatever number generating scheme
Line 2 set relative location of AndroidManifest to the working directory of script ('cordova_app' is the directory created using 'cordova create...')
Line 3 use sed and regex to replace current versionCode with desired.
Line 4 remove tmp file created by sed.

Mateusz Mucha

unread,
Dec 3, 2013, 6:58:09 AM12/3/13
to phon...@googlegroups.com
Thank you James, it looks like a good solution.


--
-- You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en
 
For more info on PhoneGap or to download the code go to www.phonegap.com
 
To compile in the cloud, check out build.phonegap.com
---
You received this message because you are subscribed to a topic in the Google Groups "phonegap" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/phonegap/ckk2h2nri4Q/unsubscribe.
To unsubscribe from this group and all its topics, send an email to phonegap+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
kind regards,
Mateusz Mucha
mus...@gmail.com

Lee Quarella

unread,
Mar 6, 2014, 12:13:20 PM3/6/14
to phon...@googlegroups.com
Are we still stuck in workaround mode, or has this been sorted out?

Mateusz Mucha

unread,
Mar 7, 2014, 6:00:02 AM3/7/14
to phon...@googlegroups.com
I've switched to plain Cordova and it sorta works for me there.  I'm not sure what it's like in Phonegap right now, but cordova doesn't override all attributes in AndroidManifest.xml (and vesionCode is one of those unaffected). So I'm editing the "version" attribute in config.xml and "versionCode" in AndroidManifest.xml. I'm not sure if that's what the devs intended (I thought I'm not supposed to keep platforms dir in version control), but hey, it works.

Diogo Rodrigues

unread,
May 21, 2014, 7:44:55 AM5/21/14
to phon...@googlegroups.com
try with android-versionCode="123" 
worked for me in Cordova 3.5.0-0.2.4

Даниэль Циммерманн

unread,
Oct 21, 2014, 3:59:56 AM10/21/14
to phon...@googlegroups.com
Thx Diogo, this worked for me as well. Strange, that the old documentation (2.9.0) mentioned a versionCode attribute, while the newest doesn't seem to mention the versionCode at all... This is kind of frustrating with Phonegap...
Reply all
Reply to author
Forward
0 new messages