Skip to content

Instantly share code, notes, and snippets.

@njleonzhang
Created September 7, 2016 05:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save njleonzhang/11a22064dd48c2503a0a205f336efc9e to your computer and use it in GitHub Desktop.
Save njleonzhang/11a22064dd48c2503a0a205f336efc9e to your computer and use it in GitHub Desktop.
append extend 8 to android code version.
#!/usr/bin/env node
var path = require('path');
var fs = require('fs');
var xml2js = require('xml2js');
function xmlFileToJs(filename, cb) {
var filepath = path.normalize(path.join(__dirname, filename));
fs.readFile(filepath, 'utf8', function (err, xmlStr) {
if (err) throw (err);
xml2js.parseString(xmlStr, {}, cb);
});
}
function jsToXmlFile(filename, obj, cb) {
var filepath = path.normalize(path.join(__dirname, filename));
var builder = new xml2js.Builder();
var xml = builder.buildObject(obj);
fs.writeFile(filepath, xml, cb);
}
var androidManifestRPath = '../../platforms/android/AndroidManifest.xml';
xmlFileToJs(androidManifestRPath, function(error, data) {
var config = data;
config.manifest.$['android:versionCode'] += '8';
jsToXmlFile(androidManifestRPath, config)
});
@ricardoapaes
Copy link

ricardoapaes commented Jan 27, 2020

This code not running with Cordova 9.0, error:

Error: Callback must be a function. Received undefined

Use this: https://gist.github.com/ricardoapaes/66f07c0a46c3e7dadf488aa66b93fff7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment