diff --git a/bin/templates/project/app/build.gradle b/bin/templates/project/app/build.gradle index ea26195f..47cef0d1 100644 --- a/bin/templates/project/app/build.gradle +++ b/bin/templates/project/app/build.gradle @@ -27,7 +27,28 @@ buildscript { } dependencies { + apply from: '../CordovaLib/cordova.gradle' + classpath 'com.android.tools.build:gradle:3.3.0' + + if(cdvHelpers.getConfigPreference('GoogleServicesEnabled', 'false').toBoolean()) { + String defaultGoogleServiceVersion = '4.2.0' + + /** + * Fetches the user's defined Google Services Plugin Version from config.xml. + * If the version is not set or invalid, it will default to the ${defaultGoogleServiceVersion} + */ + String googleServicesVersion = cdvHelpers.getConfigPreference('GoogleServicesVersion', defaultGoogleServiceVersion) + if(!cdvHelpers.isVersionValid(googleServicesVersion)) { + println("The defined Google Services plugin version (${googleServicesVersion}) does not appear to be a valid version. Falling back to version: ${defaultGoogleServiceVersion}.") + googleServicesVersion = defaultGoogleServiceVersion + } + + // Create the Google Services classpath and set it. + String googleServicesClassPath = "com.google.gms:google-services:${googleServicesVersion}" + println "Adding classpath: ${googleServicesClassPath}" + classpath googleServicesClassPath + } } } @@ -356,3 +377,7 @@ for (def func : cdvPluginPostBuildExtras) { if (hasProperty('postBuildExtras')) { postBuildExtras() } + +if (cdvHelpers.getConfigPreference('GoogleServicesEnabled', 'false').toBoolean()) { + apply plugin: 'com.google.gms.google-services' +} diff --git a/framework/cordova.gradle b/framework/cordova.gradle index 5a06ea74..0fb476c2 100644 --- a/framework/cordova.gradle +++ b/framework/cordova.gradle @@ -48,6 +48,10 @@ Version[] getAvailableBuildTools() { .sort { a, b -> a.isHigherThan(b) ? -1 : 1 } } +Boolean isVersionValid(version) { + return !(new Version(version)).isEqual('0.0.0') +} + String doFindLatestInstalledBuildTools(String minBuildToolsVersionString) { def availableBuildToolsVersions try {