Skip to content

Commit

Permalink
Merge pull request #14 from OutSystems/fix/RMET-1497/gradle-build-ext…
Browse files Browse the repository at this point in the history
…ras-crash

RMET-1497 ::: Hook to add google services dependency to build.gradle
  • Loading branch information
CarlsCorrea authored Apr 20, 2022
2 parents cb9eb82 + e0e0998 commit 7e0667c
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ The changes documented here do not include those from the original repository.

## [Unreleased]

## 5.0.0-OS3
## 2022-04-19
- Hook to add google services dependency to build.gradle. [RMET-1497](https://outsystemsrd.atlassian.net/browse/RMET-1497)

### 2021-04-18
- Added hook to enable the usage of a dynamic message for the NSUserTrackingUsageDescription field for iOS (https://outsystemsrd.atlassian.net/browse/RMET-1496)

Expand Down
50 changes: 50 additions & 0 deletions hooks/android/build_gradle_add_dependency.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env node

module.exports = function(ctx) {
var fs = require('fs'),
os = require("os"),
readline = require("readline"),
deferral = require('q').defer();

var googleServicesStr = "if (project.extensions.findByName('googleServices') == null) { apply plugin: 'com.google.gms.google-services' }"
var googleServicesStrExists = false
var classpathsStrToVerify = "com.google.gms:google-services:4.3.10"
var classpathsStr = '\t\tclasspath "com.google.gms:google-services:4.3.10"'
var rootBuildGradlePath = "platforms/android/build.gradle"
var appBuildGradlePath = "platforms/android/app/build.gradle"

var lineReader = readline.createInterface({
terminal: false,
input : fs.createReadStream(rootBuildGradlePath)
});
lineReader.on("line", function(line) {
if (!line.includes(classpathsStrToVerify)) {
fs.appendFileSync('./build.gradle', line.toString() + os.EOL);
if (/.*\ dependencies \{.*/.test(line)) {
fs.appendFileSync('./build.gradle', classpathsStr + os.EOL);
}
}

}).on("close", function () {
fs.rename('./build.gradle', rootBuildGradlePath, deferral.resolve);
});

var lineReaderApp = readline.createInterface({
terminal: false,
input : fs.createReadStream(appBuildGradlePath)
});
lineReaderApp.on("line", function (line) {
if (line.includes(googleServicesStr)) {
googleServicesStrExists = true;
}
});
lineReaderApp.on("close", function () {
if (!googleServicesStrExists) {
fs.appendFileSync('./' + appBuildGradlePath, googleServicesStr + os.EOL);
fs.rename('./' + appBuildGradlePath, appBuildGradlePath, deferral.resolve);
}

});

return deferral.promise;
};
File renamed without changes.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-firebase-analytics",
"version": "5.0.0-OS2",
"version": "5.0.0-OS3",
"description": "Cordova plugin for Firebase Analytics",
"cordova": {
"id": "cordova-plugin-firebase-analytics",
Expand Down
6 changes: 4 additions & 2 deletions plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="cordova-plugin-firebase-analytics"
version="5.0.0-OS2">
version="5.0.0-OS3">

<name>FirebaseAnalyticsPlugin</name>
<description>Cordova plugin for Firebase Analytics</description>
Expand Down Expand Up @@ -29,7 +29,7 @@ xmlns:android="http://schemas.android.com/apk/res/android"
<platform name="ios">
<preference name="IOS_FIREBASE_ANALYTICS_VERSION" default="~> 8.6.0"/>

<hook type="after_prepare" src="hooks/iOSCopyPreferences.js" />
<hook type="after_prepare" src="hooks/ios/iOSCopyPreferences.js" />

<config-file target="config.xml" parent="/*">
<feature name="FirebaseAnalytics">
Expand Down Expand Up @@ -69,6 +69,8 @@ xmlns:android="http://schemas.android.com/apk/res/android"
<platform name="android">
<preference name="ANDROID_FIREBASE_ANALYTICS_VERSION" default="19.0.+"/>

<hook type="before_plugin_install" src="hooks/android/build_gradle_add_dependency.js" />

<config-file target="res/xml/config.xml" parent="/*">
<feature name="FirebaseAnalytics">
<param name="android-package" value="by.chemerisuk.cordova.firebase.FirebaseAnalyticsPlugin" />
Expand Down

0 comments on commit 7e0667c

Please sign in to comment.