From 7f68c0e7450efb62ada1e9a485fe6bf1bac8a7fb Mon Sep 17 00:00:00 2001 From: Brendon Duncan Date: Thu, 4 Oct 2018 15:15:45 +1300 Subject: [PATCH] Only add google to build.grade if it is not already there. --- scripts/android/helper.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/scripts/android/helper.js b/scripts/android/helper.js index 488d57ab5..d37a0f23e 100644 --- a/scripts/android/helper.js +++ b/scripts/android/helper.js @@ -47,6 +47,13 @@ function addRepos(buildGradle) { // modify the actual line buildGradle = buildGradle.replace(/^(\s*)jcenter\(\)/m, modifiedLine); + var googlesMavenRepo = whitespace + 'google() // Google\'s Maven repository from cordova-plugin-firebase'; + // Only add Google's Maven repo if it's not already there + var googleRepoAlreadyExists = buildGradle.test(/(google\(\))|(https:\/\/maven\.google\.com)/m); + if (googleRepoAlreadyExists) { + googlesMavenRepo = ""; + } + // update the all projects grouping var allProjectsIndex = buildGradle.indexOf('allprojects'); if (allProjectsIndex > 0) { @@ -56,7 +63,6 @@ function addRepos(buildGradle) { // Add google() to the allprojects section of the string match = secondHalfOfFile.match(/^(\s*)jcenter\(\)/m); - var googlesMavenRepo = whitespace + 'google() // Google\'s Maven repository from cordova-plugin-firebase'; modifiedLine = match[0] + '\n' + googlesMavenRepo; // modify the part of the string that is after 'allprojects' secondHalfOfFile = secondHalfOfFile.replace(/^(\s*)jcenter\(\)/m, modifiedLine); @@ -66,7 +72,6 @@ function addRepos(buildGradle) { } else { // this should not happen, but if it does, we should try to add the dependency to the buildscript match = buildGradle.match(/^(\s*)jcenter\(\)/m); - var googlesMavenRepo = whitespace + 'google() // Google\'s Maven repository from cordova-plugin-firebase'; modifiedLine = match[0] + '\n' + googlesMavenRepo; // modify the part of the string that is after 'allprojects' buildGradle = buildGradle.replace(/^(\s*)jcenter\(\)/m, modifiedLine);