Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move from Firebase Crash to Firebase Crashlytics and stop opt-in users #784

Merged
merged 7 commits into from
Aug 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
.build-browser
package-lock.json
node_modules
cordova-plugin-firebase.code-workspace
25 changes: 16 additions & 9 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,16 @@ xmlns:android="http://schemas.android.com/apk/res/android">
<param name="onload" value="true" />
</feature>
</config-file>
<config-file parent="/resources" target="res/values/strings.xml">
<string name="google_app_id">@string/google_app_id</string>
</config-file>
<config-file parent="/resources" target="res/values/strings.xml">
<string name="google_api_key">@string/google_api_key</string>
</config-file>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the removement if those values?

<config-file target="AndroidManifest.xml" parent="/*">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
</config-file>
<config-file target="AndroidManifest.xml" parent="/manifest/application">
<service android:enabled="true" android:exported="false" android:name="com.google.android.gms.measurement.AppMeasurementService" />
<meta-data android:name="firebase_messaging_auto_init_enabled" android:value="false" />
<meta-data android:name="firebase_crashlytics_collection_enabled" android:value="false" />
<meta-data android:name="firebase_performance_collection_enabled" android:value="false" />
</config-file>
<config-file target="AndroidManifest.xml" parent="/manifest/application">
<service android:name="org.apache.cordova.firebase.FirebasePluginMessagingService">
Expand All @@ -58,11 +55,9 @@ xmlns:android="http://schemas.android.com/apk/res/android">
<source-file src="src/android/colors.xml" target-dir="res/values" />

<framework src="src/android/build.gradle" custom="true" type="gradleReference" />
<framework src="com.google.gms:google-services:+" />
<framework src="com.google.android.gms:play-services-tagmanager:+" />
<framework src="com.google.firebase:firebase-core:+" />
<framework src="com.google.firebase:firebase-messaging:+" />
<framework src="com.google.firebase:firebase-crash:+" />
<framework src="com.google.firebase:firebase-config:+" />
<framework src="com.google.firebase:firebase-perf:+" />

Expand All @@ -84,6 +79,15 @@ xmlns:android="http://schemas.android.com/apk/res/android">
<config-file parent="aps-environment" target="*/Entitlements-Release.plist">
<string>production</string>
</config-file>
<config-file parent="FirebaseMessagingAutoInitEnabled" target="*-Info.plist">
<string>no</string>
</config-file>
<config-file parent="firebase_performance_collection_enabled" target="*-Info.plist">
<false />
</config-file>
<config-file parent="firebase_crashlytics_collection_enabled" target="*-Info.plist">
<false />
</config-file>

<resource-file src="src/ios/GoogleService-Info.plist" />

Expand All @@ -103,7 +107,8 @@ xmlns:android="http://schemas.android.com/apk/res/android">
<framework custom="true" src="src/ios/Firebase/Analytics/nanopb.framework" />
<framework custom="true" src="src/ios/Firebase/Messaging/Protobuf.framework" />
<framework custom="true" src="src/ios/Firebase/Messaging/FirebaseMessaging.framework" />
<framework custom="true" src="src/ios/Firebase/Crash/FirebaseCrash.framework" />
<framework custom="true" src="src/ios/Firebase/Crashlytics/Fabric.framework" />
<framework custom="true" src="src/ios/Firebase/Crashlytics/Crashlytics.framework" />
<framework custom="true" src="src/ios/Firebase/RemoteConfig/FirebaseRemoteConfig.framework" />
<framework custom="true" src="src/ios/Firebase/RemoteConfig/FirebaseABTesting.framework" />
<framework custom="true" src="src/ios/Firebase/Auth/FirebaseAuth.framework" />
Expand All @@ -120,4 +125,6 @@ xmlns:android="http://schemas.android.com/apk/res/android">
</platform>

<hook src="scripts/after_prepare.js" type="after_prepare" />
<hook src="scripts/after_plugin_add.js" type="after_plugin_add" />
<hook src="scripts/before_plugin_rm.js" type="before_plugin_rm" />
</plugin>
24 changes: 24 additions & 0 deletions scripts/after_plugin_add.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

var androidHelper = require('./lib/android-helper');
var iosHelper = require("./lib/ios-helper");
var utilities = require("./lib/utilities");

module.exports = function(context) {

var platforms = context.opts.cordova.platforms;

// Modify the Gradle build file to add a task that will upload the debug symbols
// at build time.
if (platforms.indexOf("android") !== -1) {
androidHelper.removeFabricBuildToolsFromGradle();
androidHelper.addFabricBuildToolsGradle();
}

// Add a build phase which runs a shell script that executes the Crashlytics
// run command line tool which uploads the debug symbols at build time.
if (platforms.indexOf("ios") !== -1) {
var xcodeProjectPath = utilities.getXcodeProjectPath(context);
iosHelper.removeShellScriptBuildPhase(context, xcodeProjectPath);
iosHelper.addShellScriptBuildPhase(context, xcodeProjectPath);
}
};
194 changes: 87 additions & 107 deletions scripts/after_prepare.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env node

'use strict';

/**
Expand All @@ -10,15 +11,15 @@ var fs = require('fs');
var path = require('path');

fs.ensureDirSync = function (dir) {
if (!fs.existsSync(dir)) {
dir.split(path.sep).reduce(function (currentPath, folder) {
currentPath += folder + path.sep;
if (!fs.existsSync(currentPath)) {
fs.mkdirSync(currentPath);
}
return currentPath;
}, '');
}
if (!fs.existsSync(dir)) {
dir.split(path.sep).reduce(function (currentPath, folder) {
currentPath += folder + path.sep;
if (!fs.existsSync(currentPath)) {
fs.mkdirSync(currentPath);
}
return currentPath;
}, '');
}
};

var config = fs.readFileSync('config.xml').toString();
Expand All @@ -28,114 +29,93 @@ var IOS_DIR = 'platforms/ios';
var ANDROID_DIR = 'platforms/android';

var PLATFORM = {
IOS: {
dest: [
IOS_DIR + '/' + name + '/Resources/GoogleService-Info.plist',
IOS_DIR + '/' + name + '/Resources/Resources/GoogleService-Info.plist'
],
src: [
'GoogleService-Info.plist',
IOS_DIR + '/www/GoogleService-Info.plist',
'www/GoogleService-Info.plist'
]
},
ANDROID: {
dest: [
ANDROID_DIR + '/google-services.json'
],
src: [
'google-services.json',
ANDROID_DIR + '/assets/www/google-services.json',
'www/google-services.json'
],
stringsXml: fileExists(ANDROID_DIR + '/app/src/main/res/values/strings.xml') ? ANDROID_DIR + '/app/src/main/res/values/strings.xml' : ANDROID_DIR + '/res/values/strings.xml'
}
IOS: {
dest: [
IOS_DIR + '/' + name + '/Resources/GoogleService-Info.plist',
IOS_DIR + '/' + name + '/Resources/Resources/GoogleService-Info.plist'
],
src: [
'GoogleService-Info.plist',
IOS_DIR + '/www/GoogleService-Info.plist',
'www/GoogleService-Info.plist'
]
},
ANDROID: {
dest: [
ANDROID_DIR + '/google-services.json',
ANDROID_DIR + '/app/google-services.json'
],
src: [
'google-services.json',
ANDROID_DIR + '/assets/www/google-services.json',
'www/google-services.json'
],
stringsXml: fileExists(ANDROID_DIR + '/app/src/main/res/values/strings.xml') ? ANDROID_DIR + '/app/src/main/res/values/strings.xml' : ANDROID_DIR + '/res/values/strings.xml'
}
};

function updateStringsXml(contents) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this out of scope of the PR?

var json = JSON.parse(contents);
var strings = fs.readFileSync(PLATFORM.ANDROID.stringsXml).toString();

// strip non-default value
strings = strings.replace(new RegExp('<string name="google_app_id">([^\@<]+?)</string>', 'i'), '');

// strip non-default value
strings = strings.replace(new RegExp('<string name="google_api_key">([^\@<]+?)</string>', 'i'), '');

// strip empty lines
strings = strings.replace(new RegExp('(\r\n|\n|\r)[ \t]*(\r\n|\n|\r)', 'gm'), '$1');

// replace the default value
strings = strings.replace(new RegExp('<string name="google_app_id">([^<]+?)</string>', 'i'), '<string name="google_app_id">' + json.client[0].client_info.mobilesdk_app_id + '</string>');

// replace the default value
strings = strings.replace(new RegExp('<string name="google_api_key">([^<]+?)</string>', 'i'), '<string name="google_api_key">' + json.client[0].api_key[0].current_key + '</string>');

fs.writeFileSync(PLATFORM.ANDROID.stringsXml, strings);
}

function copyKey(platform, callback) {
for (var i = 0; i < platform.src.length; i++) {
var file = platform.src[i];
if (fileExists(file)) {
try {
var contents = fs.readFileSync(file).toString();

try {
platform.dest.forEach(function (destinationPath) {
var folder = destinationPath.substring(0, destinationPath.lastIndexOf('/'));
fs.ensureDirSync(folder);
fs.writeFileSync(destinationPath, contents);
});
} catch (e) {
// skip
}
function copyKey (platform, callback) {
for (var i = 0; i < platform.src.length; i++) {
var file = platform.src[i];
if (fileExists(file)) {
try {
var contents = fs.readFileSync(file).toString();

try {
platform.dest.forEach(function (destinationPath) {
var folder = destinationPath.substring(0, destinationPath.lastIndexOf('/'));
fs.ensureDirSync(folder);
fs.writeFileSync(destinationPath, contents);
});
} catch (e) {
// skip
}

callback && callback(contents);
} catch (err) {
console.log(err)
}
callback && callback(contents);
} catch (err) {
console.log(err);
}

break;
}
break;
}
}
}

function getValue(config, name) {
var value = config.match(new RegExp('<' + name + '>(.*?)</' + name + '>', 'i'));
if (value && value[1]) {
return value[1]
} else {
return null
}
function getValue (config, name) {
var value = config.match(new RegExp('<' + name + '>(.*?)</' + name + '>', 'i'));
if (value && value[1]) {
return value[1];
} else {
return null;
}
}

function fileExists(path) {
try {
return fs.statSync(path).isFile();
} catch (e) {
return false;
}
function fileExists (path) {
try {
return fs.statSync(path).isFile();
} catch (e) {
return false;
}
}

function directoryExists(path) {
try {
return fs.statSync(path).isDirectory();
} catch (e) {
return false;
}
function directoryExists (path) {
try {
return fs.statSync(path).isDirectory();
} catch (e) {
return false;
}
}

module.exports = function(context) {
//get platform from the context supplied by cordova
var platforms = context.opts.platforms;
// Copy key files to their platform specific folders
if (platforms.indexOf('ios') !== -1 && directoryExists(IOS_DIR)) {
console.log('Preparing Firebase on iOS');
copyKey(PLATFORM.IOS);
}
if (platforms.indexOf('android') !== -1 && directoryExists(ANDROID_DIR)) {
console.log('Preparing Firebase on Android');
copyKey(PLATFORM.ANDROID, updateStringsXml)
}
};
module.exports = function (context) {
//get platform from the context supplied by cordova
var platforms = context.opts.platforms;
// Copy key files to their platform specific folders
if (platforms.indexOf('ios') !== -1 && directoryExists(IOS_DIR)) {
console.log('Preparing Firebase on iOS');
copyKey(PLATFORM.IOS);
}
if (platforms.indexOf('android') !== -1 && directoryExists(ANDROID_DIR)) {
console.log('Preparing Firebase on Android');
copyKey(PLATFORM.ANDROID);
}
};
20 changes: 20 additions & 0 deletions scripts/before_plugin_rm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

var androidHelper = require('./lib/android-helper');
var iosHelper = require("./lib/ios-helper");
var utilities = require("./lib/utilities");

module.exports = function(context) {

var platforms = context.opts.cordova.platforms;

// Remove the Gradle modifications that were added when the plugin was installed.
if (platforms.indexOf("android") !== -1) {
androidHelper.removeFabricBuildToolsFromGradle();
}

// Remove the build script that was added when the plugin was installed.
if (platforms.indexOf("ios") !== -1) {
var xcodeProjectPath = utilities.getXcodeProjectPath(context);
iosHelper.removeShellScriptBuildPhase(context, xcodeProjectPath);
}
};
43 changes: 43 additions & 0 deletions scripts/lib/android-helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
var fs = require("fs");
var path = require("path");
var utilities = require("./utilities");

module.exports = {

addFabricBuildToolsGradle: function () {

var buildGradle = utilities.readBuildGradle();

var addToBuildGradle = [
"",
"// Fabric Cordova Plugin - Start Fabric Build Tools ",
"buildscript {",
" repositories {",
" maven { url 'https://maven.fabric.io/public' }",
" maven { url 'https://maven.google.com' }",
" }",
" dependencies {",
" classpath 'io.fabric.tools:gradle:1.25.4'",
" classpath 'com.google.gms:google-services:+'",
" }",
"}",
"",
"apply plugin: 'io.fabric'",
"apply plugin: 'com.google.gms.google-services'",
"// Fabric Cordova Plugin - End Fabric Build Tools"
].join("\n");

buildGradle = buildGradle.replace(/(\/\/ PLUGIN GRADLE EXTENSIONS START)/, addToBuildGradle + '\n\n$1');

utilities.writeBuildGradle(buildGradle);
},

removeFabricBuildToolsFromGradle: function () {

var buildGradle = utilities.readBuildGradle();

buildGradle = buildGradle.replace(/\n\/\/ Fabric Cordova Plugin - Start Fabric Build Tools[\s\S]*\/\/ Fabric Cordova Plugin - End Fabric Build Tools/, "");

utilities.writeBuildGradle(buildGradle);
}
};
Loading