Release problem with Android app version code, Please help


#1

Please help, I tried mostly everything I could find.

I somehow managed to make the the automated build uploaded a app version with 6 digits to the play store a while ago. I didn’t realize it the version code was 6 digits and approved it.
However, seems the default code length is 5 digits. The old version is now too large and I can not top it with my builds. They always end up to be 5 digits and hence too small numbers.

The main problem is that one can’t delete an uploaded & released version from the store.
Feeling that if I do not find a reasonable solution I would have to create a new App and move users to it…

I can not find a way how to set / force the version code manually beforeor after building the APK.

Based on this I went through the build.gradle file and disabled ll 158 for instance

versionCode versionCodeOverride ?: Integer.parseInt("" + privateHelpers.extractIntFromManifest("versionCode") + "0")

but to no avail. I could not update my app for a month now. Please help.

This is a more desperate re-post of my previous post


#2

Ok, took me a while, but to fix this one has to split

cordova build --release android
into

cordova prepare android
./adjustVersionCode.py 
cordova compile android --release

with adjustVersionCode.py in un-optimized and cleaned python:

#!/usr/bin/env python

from lxml import etree

lines = ''
with open('config.xml','r') as configFile:
    for line in configFile.readlines():
        lines += line

configXML = etree.fromstring(lines)

versionNumber = configXML.attrib['version']
versionCode = versionNumber.replace('.','')

if len(versionCode) < 6:
    versionCode += '0'

print versionNumber,versionCode


lines = ''
with open('./platforms/android/AndroidManifest.xml','r') as configFile:
    for line in configFile.readlines():
        lines += line

androidManifestXML = etree.fromstring(lines)

wrongVersion = androidManifestXML.attrib['{http://schemas.android.com/apk/res/android}versionCode']

replaceString = 'android:versionCode="'+str(wrongVersion)+'"'
replaceWith = 'android:versionCode="'+str(versionCode)+'"'

lines = ''
with open('./platforms/android/AndroidManifest.xml','r') as configFile:
    for line in configFile.readlines():
        lines += line.replace(replaceString,replaceWith)


with open('./platforms/android/AndroidManifest.xml','w') as configFile:
    for line in lines:
        configFile.write(line)

#3

Thanks for sharing.

Is it a bug in last cordova client?


#4

answer and workaround here:


#5

I found this forum and almost started to think about python solution as @elduderino15 suggested, but @LAFONT solution is simpler and better.
Put android-versionCode="xxxxxx" in config.xml
<widget id="com.xxxxx.yyyyyyyyyyy" android-versionCode="201010" version="2.1.1" ......>


#6

Thanks for the link! I upgraded my project to io2 and was certain I forgot how to fix this problem… :smiley:


#7

Here’s a gawk version that outputs the corrected version on stdout, incase you don’t like introducing python and lxml/pip dependencies:

gawk '/^<manifest / {
     match($0, /android:versionCode="([0-9]+)"/, m);
     code = substr($0, m[1, "start"], m[1, "length"]);
     while (length(code) < 6)
       code = code "0";
     res = substr($0, 1, m[1, "start"]-1) code substr($0,  m[1, "start"]-1 + m[1, "length"] + 1)
     print res;
     next;
  }
  {print}' INFILE > OUTFILE

#8

I’ve lost 1 day with this shit. You saved me.


#9

I have test. it works !


#10

I have test. It works ! Thank you bro.