niCad niCad - 8 months ago 60
Android Question

Cordova Android App's Version Number Changes in Gradle

I am trying to submit my App, and the version does not come out as expected, always append the number 8 on the Playstore (which results to 302038)

I already tried removing and adding the same Android platform. Changing the version from Android Studio's Project Structure seems to not help either.. Where else should I look?

I would really appreciate any advise, thanks in advance

Cordova: 6.0.0

Android Platform: 4.1.1

<?xml version='1.0' encoding='utf-8'?>
<widget id=.. version="3.2.03" xmlns="" xmlns:cdv="">
<author email="" href="">
<content src="index.html" />
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />

<platform name="android">
<allow-intent href="market:*" />
<preference name="android-minSdkVersion" value="14" />
<preference name="android-targetSdkVersion" value ="16" />
<preference name="Orientation" value="sensorLandscape" />
<preference name="AndroidPersistentFileLocation" value="Compatibility" />
<!--<preference name="android-hardwareAccelerated" value="false" />
<preference name="android-windowSoftInputMode" value="adjustPan" /> -->

To make the fix run every build, I made a hook in config.xml just below the platform tag:

<platform name="android">
<hook type="before_build" src="scripts/androidVersionFix.js" />

at the scripts folder, the androidVersionFix.js:

#!/usr/bin/env node


----the file creates:-----------
# In <your-project>/platforms/android/
where 30203 is the android-versionCode from config.xml


var configXml = 'config.xml';

var fs = require('fs');
var exec = require('child_process').exec;
var appVersion = '';
var fileContents = function() {
return "#Android version code fix: In <your-project>/platforms/android/ \\n \
var command = "sed -n 's/.*android-versionCode=\"\\([^\"]*\\).*/\\1/p' ";

exec(command + configXml, function(e,out,err){
appVersion = out;
console.log('echo creating, app Version: ' + appVersion);
exec('echo "'+fileContents()+'" > ./platforms/android/');


Yes its a problem of build.gradle from there its fetching and do not edit build.gradle. Do one thing create file in platform/android and paste this cdvVersionCode=3.2.03 statement to It should work