Reputation: 92
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="[email protected]" 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');
});
Upvotes: 1
Views: 1334
Reputation: 11935
This looks like an unresolved bug in cordova 5.0.0 and above. This link has more info on the same. After having looking at the build.gradle file under platforms\android folder, the following code seems to be doing the manipulation of version number,
if (Boolean.valueOf(cdvBuildMultipleApks)) {
productFlavors {
armv7 {
versionCode defaultConfig.versionCode + 2
ndk {
abiFilters "armeabi-v7a", ""
}
}
x86 {
versionCode defaultConfig.versionCode + 4
ndk {
abiFilters "x86", ""
}
}
all {
ndk {
abiFilters "all", ""
}
}
}
} else if (!cdvVersionCode) {
def minSdkVersion = cdvMinSdkVersion ?: privateHelpers.extractIntFromManifest("minSdkVersion")
// Vary versionCode by the two most common API levels:
// 14 is ICS, which is the lowest API level for many apps.
// 20 is Lollipop, which is the lowest API level for the updatable system webview.
if (minSdkVersion >= 20) {
defaultConfig.versionCode += 9
} else if (minSdkVersion >= 14) {
defaultConfig.versionCode += 8
}
}
To get away from the problem, you may remove the offending code build.gradle which does not cause any harm.
Upvotes: 1
Reputation: 71
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
Upvotes: 1
Reputation: 931
You need to update inside AndroidManifest.xml, not config.xml.
Upvotes: 0