Skip to content

Commit

Permalink
Merge branch 'dev' to master
Browse files Browse the repository at this point in the history
  • Loading branch information
dpa99c committed Sep 24, 2020
2 parents 02a7f94 + 108490a commit 2b61e90
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
* (iOS) Check if file contents for `pn-actions.json` exists before attempting to use it.
* Resolves [#512](https://github.com/dpa99c/cordova-plugin-firebasex/issues/512).
* Bug introduced by PR [#482](https://github.com/dpa99c/cordova-plugin-firebasex/pull/482).
* (Android) Add the Firebase Performance Monitoring Gradle plugin to monitor network traffic.
* Resolves [#520](https://github.com/dpa99c/cordova-plugin-firebasex/issues/520).

# Version 11.0.1
* (iOS) Set the Sign In with Apple capability based on the `IOS_ENABLE_APPLE_SIGNIN` plugin variable.
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,13 @@ The following plugin variables are used to specify the Firebase SDK versions as
- `ANDROID_FIREBASE_CRASHLYTICS_VERSION`
- `ANDROID_FIREBASE_CRASHLYTICS_NDK_VERSION`
- `ANDROID_GSON_VERSION`
- `ANDROID_FIREBASE_PERF_GRADLE_PLUGIN_VERSION`
See [Specifying Android library versions](#specifying-android-library-versions) for more info.

- `ANDROID_ICON_ACCENT` - sets the default accent color for system notifications. See [Android Notification Color](#android-notification-color) for more info.
- `ANDROID_FIREBASE_CONFIG_FILEPATH` - sets a custom filepath to `google-services.json` file as a path relative to the project root
- e.g. `--variable ANDROID_FIREBASE_CONFIG_FILEPATH="resources/android/google-services.json"`
- `ANDROID_FIREBASE_PERF_GRADLE_PLUGIN_VERSION` - overrides the default version of the [Firebase Performance Monitoring Gradle plugin for Android](https://firebase.google.com/docs/perf-mon/get-started-android?authuser=0#add-perfmon-plugin)

### iOS only
- `IOS_STRIP_DEBUG` - prevents symbolification of all libraries included via Cocoapods. See [Strip debug symbols](#strip-debug-symbols) for more info.
Expand Down
1 change: 1 addition & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
<preference name="ANDROID_FIREBASE_CRASHLYTICS_VERSION" default="17.2.1" />
<preference name="ANDROID_FIREBASE_CRASHLYTICS_NDK_VERSION" default="17.2.1" />
<preference name="ANDROID_GSON_VERSION" default="2.8.6" />
<preference name="ANDROID_FIREBASE_PERF_GRADLE_PLUGIN_VERSION" default="1.3.1" />

<framework src="com.google.android.gms:play-services-tagmanager:$ANDROID_PLAY_SERVICES_TAGMANAGER_VERSION" />
<framework src="com.google.android.gms:play-services-auth:$ANDROID_PLAY_SERVICES_AUTH_VERSION" />
Expand Down
41 changes: 26 additions & 15 deletions scripts/after_prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
var fs = require('fs');
var path = require("path");
var Utilities = require("./lib/utilities");
var utilities = require("./lib/utilities");

var appName;
var pluginVariables = {};
Expand All @@ -21,8 +21,8 @@ var PLUGIN_ID;
var PLATFORM;

var setupEnv = function(){
appName = Utilities.getAppName();
PLUGIN_ID = Utilities.getPluginId();
appName = utilities.getAppName();
PLUGIN_ID = utilities.getPluginId();
PLATFORM = {
IOS: {
dest: IOS_DIR + '/' + appName + '/Resources/GoogleService-Info.plist',
Expand All @@ -44,8 +44,12 @@ var setupEnv = function(){
ANDROID_DIR + '/app/src/main/google-services.json'
],
colorsXml: {
src: './plugins/' + Utilities.getPluginId() + '/src/android/colors.xml',
src: './plugins/' + utilities.getPluginId() + '/src/android/colors.xml',
target: ANDROID_DIR + '/app/src/main/res/values/colors.xml'
},
performanceGradlePlugin: {
classDef: 'com.google.firebase:perf-plugin',
pluginDef: 'com.google.firebase.firebase-perf'
}
}
};
Expand All @@ -54,26 +58,29 @@ var setupEnv = function(){
module.exports = function(context){
//get platform from the context supplied by cordova
var platforms = context.opts.platforms;
Utilities.setContext(context);
utilities.setContext(context);
setupEnv();

pluginVariables = Utilities.parsePluginVariables();
pluginVariables = utilities.parsePluginVariables();

// set platform key path from plugin variable
if(pluginVariables.ANDROID_FIREBASE_CONFIG_FILEPATH) PLATFORM.ANDROID.src = [pluginVariables.ANDROID_FIREBASE_CONFIG_FILEPATH];
if(pluginVariables.IOS_FIREBASE_CONFIG_FILEPATH) PLATFORM.IOS.src = [pluginVariables.IOS_FIREBASE_CONFIG_FILEPATH];


// Copy key files to their platform specific folders
if(platforms.indexOf('android') !== -1 && Utilities.directoryExists(ANDROID_DIR)){
Utilities.log('Preparing Firebase on Android');
Utilities.copyKey(PLATFORM.ANDROID);
if(platforms.indexOf('android') !== -1 && utilities.directoryExists(ANDROID_DIR)){
utilities.log('Preparing Firebase on Android');
utilities.copyKey(PLATFORM.ANDROID);

var androidHelper = require("./lib/android");

// Apply colours
if(!fs.existsSync(path.resolve(PLATFORM.ANDROID.colorsXml.target))){
fs.copyFileSync(path.resolve(PLATFORM.ANDROID.colorsXml.src), path.resolve(PLATFORM.ANDROID.colorsXml.target));
}

const $colorsXml = Utilities.parseXmlFileToJson(PLATFORM.ANDROID.colorsXml.target, {compact: true});
const $colorsXml = utilities.parseXmlFileToJson(PLATFORM.ANDROID.colorsXml.target, {compact: true});
var accentColor = pluginVariables.ANDROID_ICON_ACCENT,
$resources = $colorsXml.resources,
existingAccent = false,
Expand Down Expand Up @@ -113,14 +120,18 @@ module.exports = function(context){
}

if(writeChanges){
Utilities.writeJsonToXmlFile($colorsXml, PLATFORM.ANDROID.colorsXml.target);
Utilities.log('Updated colors.xml with accent color');
utilities.writeJsonToXmlFile($colorsXml, PLATFORM.ANDROID.colorsXml.target);
utilities.log('Updated colors.xml with accent color');
}

// Add Performance Monitoring gradle plugin for Android network traffic
androidHelper.addDependencyToRootGradle(PLATFORM.ANDROID.performanceGradlePlugin.classDef+":"+pluginVariables["ANDROID_FIREBASE_PERF_GRADLE_PLUGIN_VERSION"]);
androidHelper.applyPluginToAppGradle(PLATFORM.ANDROID.performanceGradlePlugin.pluginDef);
}

if(platforms.indexOf('ios') !== -1 && Utilities.directoryExists(IOS_DIR)){
Utilities.log('Preparing Firebase on iOS');
Utilities.copyKey(PLATFORM.IOS);
if(platforms.indexOf('ios') !== -1 && utilities.directoryExists(IOS_DIR)){
utilities.log('Preparing Firebase on iOS');
utilities.copyKey(PLATFORM.IOS);

var helper = require("./ios/helper");
var xcodeProjectPath = helper.getXcodeProjectPath();
Expand Down
37 changes: 37 additions & 0 deletions scripts/lib/android.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Android-specific utilities
*/
const fs = require('fs');
const path = require('path');
const utilities = require("./utilities");

const ANDROID_PROJECT_ROOT = 'platforms/android';
const ROOT_GRADLE_FILEPATH = ANDROID_PROJECT_ROOT + '/build.gradle';
const APP_GRADLE_FILEPATH = ANDROID_PROJECT_ROOT + '/app/build.gradle';

const gradleDependencyTemplate = "classpath '{artifactDef}'";
const applyPluginTemplate = "apply plugin: '{pluginDef}'";

const Android = {};

Android.addDependencyToRootGradle = function(artifactDef){
const gradleDependency = gradleDependencyTemplate.replace("{artifactDef}", artifactDef);
let rootGradle = fs.readFileSync(path.resolve(ROOT_GRADLE_FILEPATH)).toString();
if(rootGradle.match(gradleDependency)) return; // already exists

rootGradle = rootGradle.replace("dependencies {", "dependencies {\n"+gradleDependency);
fs.writeFileSync(path.resolve(ROOT_GRADLE_FILEPATH), rootGradle);
utilities.log("Added dependency to root gradle: " + artifactDef);
};

Android.applyPluginToAppGradle = function(pluginDef){
const applyPlugin = applyPluginTemplate.replace("{pluginDef}", pluginDef);
let appGradle = fs.readFileSync(path.resolve(APP_GRADLE_FILEPATH)).toString();
if(appGradle.match(applyPlugin)) return; // already exists

appGradle += "\n"+applyPlugin;
fs.writeFileSync(path.resolve(APP_GRADLE_FILEPATH), appGradle);
utilities.log("Applied plugin to app gradle: " + pluginDef);
};

module.exports = Android;

0 comments on commit 2b61e90

Please sign in to comment.