Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

building with cordova for android creates wrong version code

running the command cordova build --release android produces an apk that has a version code of 70. in the config.xml file, for the widget i have set it as

<widget id="com.example.myapp"
        android-versionCode="7"
        version="0.9.1"
        >

How do I get cordova-cli to build an apk with version code 7?

Running aapt.exe l -a on the generated apk shows A: android:versionCode(0x0101021b)=(type 0x10)0x46 0x46 being 70, if I jarsigner the apk, and zipalign and upload, google also tells me the version code is 70.

like image 349
gattsbr Avatar asked Jun 15 '15 20:06

gattsbr


2 Answers

I found the answer to my problem in that under platforms/android/build.gradle, on line 178,

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

at the end is that + "0" thus turning my version code from 7 to 70. Removing the + "0" at the end and changing line 178 to the following solved this problem.

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

Running aapt.exe l -a on the generated apk now shows A: android:versionCode(0x0101021b)=(type 0x10)0x7

like image 73
gattsbr Avatar answered Nov 07 '22 08:11

gattsbr


I had the same issue, I'm using Cordova 4.3.0. My versionCode in the AndroidManifest.xml was "1" and the versionCode in the .apk was coming through as "12". If you look at the chunk of code after the line you reference, building multiple versions will append a "2" for arm7 and a "4" for x86. I sort of see why this was done, but it seems to me it's better to let developers determine the versionCode they want.

like image 25
Chi-An Avatar answered Nov 07 '22 10:11

Chi-An