Skip to content

Commit

Permalink
Merge pull request #15 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 committed Apr 20, 2022
2 parents 2f29d5f + f055808 commit 9bde9c3
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

The changes documented here do not include those from the original repository.

## [3.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-11-05
- New plugin release to include metadata tag setting compatibility with MABS versions

## [3.0.0-OS2]

## 2021-11-05
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;
};
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-crash",
"version": "3.0.0-OS2",
"version": "3.0.0-OS3",
"description": "Cordova plugin for Firebase Crashlytics",
"cordova": {
"id": "cordova-plugin-firebase-crash",
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-crash"
version="3.0.0-OS2">
version="3.0.0-OS3">

<name>cordova-plugin-firebase-crash</name>
<description>Cordova plugin for Firebase Crashlytics</description>
Expand All @@ -16,7 +16,7 @@ xmlns:android="http://schemas.android.com/apk/res/android"
<engine name="cordova-ios" version=">=5.1.1"/>
</engines>

<dependency id="cordova-plugin-firebase-analytics" url="https://github.com/OutSystems/cordova-plugin-firebase-analytics.git#5.0.0-OS2"/>
<dependency id="cordova-plugin-firebase-analytics" url="https://github.com/OutSystems/cordova-plugin-firebase-analytics.git#5.0.0-OS3"/>

<js-module src="www/FirebaseCrash.js" name="FirebaseCrash">
<merges target="cordova.plugins.firebase.crashlytics" />
Expand Down Expand Up @@ -65,6 +65,8 @@ xmlns:android="http://schemas.android.com/apk/res/android"
<platform name="android">
<preference name="ANDROID_FIREBASE_CRASHLYTICS_VERSION" default="18.2.+"/>

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

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

0 comments on commit 9bde9c3

Please sign in to comment.