Skip to content

Instantly share code, notes, and snippets.

@ianlintner-wf
Last active February 19, 2019 10:10
Show Gist options
  • Save ianlintner-wf/9b042900cd70b518b506fb989d7085c0 to your computer and use it in GitHub Desktop.
Save ianlintner-wf/9b042900cd70b518b506fb989d7085c0 to your computer and use it in GitHub Desktop.
This is to fix version issues between multiple google services plugins in Ionic & cordova builds. Cordova before_prepare hook.
#!/usr/bin/env node
// Define hook in your config <hook src="scripts/cordova-google-services-version-gradle-fix.js" type="before_prepare" />
var sourceDir = '';
var platformDir = 'platforms/android';
var fs = require('fs');
var path = require('path');
var readline = require("readline");
module.exports = function(ctx) {
console.log('-----------------------------');
console.log('Gradle Fix');
if (ctx.opts.platforms.indexOf('android') < 0) {
return;
}
var Q = ctx.requireCordovaModule('q');
var deferred = Q.defer();
var platformRoot = path.join(ctx.opts.projectRoot, 'platforms/android');
var gradle = path.join(platformRoot, 'project.properties');
console.log(gradle);
fs.readFile(gradle, 'utf8', function (err,data) {
if (err) {
console.log(err);
deferred.reject(err);
}
var result = data.replace(/play-services-auth:.*/g, 'play-services-auth:9.8.0')
.replace(/play-services-identity:.*/g, 'play-services-identity:9.8.0');
fs.writeFile(gradle, result, 'utf8', function (err) {
if (err) {
console.log('error');
console.log('-----------------------------');
deferred.reject(err);
}
console.log('complete');
console.log('-----------------------------');
deferred.resolve();
});
});
return deferred.promise;
};
@kfrijters
Copy link

Thank you, worked like a charm! just had to change FCM_VERSION to a more recent version

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