niCad niCad - 5 months ago 39
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="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>Test</name>
<description>
..bla
</description>
<author email="a@a.com" href="http://www.web.com">
Author
</author>
<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" /> -->
</platform>
</widget>





Edit
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/gradle.properties
cdvVersionCode=30203
---------------------------------
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/gradle.properties \\n \
cdvVersionCode="+appVersion
};
var command = "sed -n 's/.*android-versionCode=\"\\([^\"]*\\).*/\\1/p' ";


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

Answer

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