Skip to content

Commit

Permalink
BREAKING CHANGE: (Android, iOS) Migrate from Fabric Crashlytics to Fi…
Browse files Browse the repository at this point in the history
…rebase Crashlytics.

Resolves #335.
  • Loading branch information
dpa99c committed Jun 18, 2020
1 parent a2030bf commit d6c60a2
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 167 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
* *BREAKING CHANGE:* (Android, iOS) Migrate from Fabric Crashlytics to Firebase Crashlytics.
** Based on [this commit](https://github.com/vickydlion/cordova-plugin-firebasex/commit/0dfb5753edcd9fc19a0e7a52fdd4fc79d6d976ea) in [PR #432](https://github.com/dpa99c/cordova-plugin-firebasex/pull/432)
** Resolves [#335](https://github.com/dpa99c/cordova-plugin-firebasex/issues/335).
** Removes `isCrashlyticsCollectionCurrentlyEnabled()` as it's no longer necessary to manually init Crashlytics and a runtime method exists to enable/disable it.

# Version 9.1.2
* (Android) Fix retrieval of auth provider ID - [see here for more info](https://github.com/firebase/FirebaseUI-Android/issues/329#issuecomment-564409912)
* (iOS) Align retrieval of auth provider ID with Android.
Expand Down
33 changes: 6 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ To help ensure this plugin is kept updated, new features are added and bugfixes
- [Crashlytics](#crashlytics)
- [setCrashlyticsCollectionEnabled](#setcrashlyticscollectionenabled)
- [isCrashlyticsCollectionEnabled](#iscrashlyticscollectionenabled)
- [isCrashlyticsCollectionCurrentlyEnabled](#iscrashlyticscollectioncurrentlyenabled)
- [setCrashlyticsUserId](#setcrashlyticsuserid)
- [sendCrash](#sendcrash)
- [logMessage](#logmessage)
Expand Down Expand Up @@ -202,8 +201,8 @@ The following plugin variables are used to specify the Firebase SDK versions as
- `ANDROID_FIREBASE_AUTH_VERSION`
- `$ANDROID_FIREBASE_INAPPMESSAGING_VERSION`
- `ANDROID_FIREBASE_FIRESTORE_VERSION`
- `ANDROID_CRASHLYTICS_VERSION`
- `ANDROID_CRASHLYTICS_NDK_VERSION`
- `ANDROID_FIREBASE_CRASHLYTICS_VERSION`
- `ANDROID_FIREBASE_CRASHLYTICS_NDK_VERSION`
- `ANDROID_GSON_VERSION`
See [Specifying Android library versions](#specifying-android-library-versions) for more info.

Expand Down Expand Up @@ -375,8 +374,8 @@ The following plugin variables are used to specify the following Gradle dependen
- `ANDROID_FIREBASE_AUTH_VERSION` => `com.google.firebase:firebase-auth`
- `ANDROID_FIREBASE_FIRESTORE_VERSION` => `com.google.firebase:firebase-firestore`
- `$ANDROID_FIREBASE_INAPPMESSAGING_VERSION` => `com.google.firebase:firebase-inappmessaging-display`
- `ANDROID_CRASHLYTICS_VERSION` => `com.crashlytics.sdk.android:crashlytics`
- `ANDROID_CRASHLYTICS_NDK_VERSION` => `com.crashlytics.sdk.android:crashlytics-ndk`
- `ANDROID_FIREBASE_CRASHLYTICS_VERSION` => `com.google.firebase:firebase-crashlytics`
- `ANDROID_FIREBASE_CRASHLYTICS_NDK_VERSION` => `com.google.firebase:firebase-crashlytics-ndk`
- `ANDROID_GSON_VERSION` => `com.google.code.gson:gson`

For example:
Expand All @@ -389,8 +388,8 @@ For example:
--variable ANDROID_FIREBASE_CONFIG_VERSION=18.0.0 \
--variable ANDROID_FIREBASE_PERF_VERSION=18.0.0 \
--variable ANDROID_FIREBASE_AUTH_VERSION=18.0.0 \
--variable ANDROID_CRASHLYTICS_VERSION=2.10.1 \
--variable ANDROID_CRASHLYTICS_NDK_VERSION=2.1.0 \
--variable ANDROID_FIREBASE_CRASHLYTICS_VERSION=17.0.1 \
--variable ANDROID_FIREBASE_CRASHLYTICS_NDK_VERSION=17.0.1 \
### AndroidX
This plugin has been migrated to use [AndroidX (Jetpack)](https://developer.android.com/jetpack/androidx/migrate) which is the successor to the [Android Support Library](https://developer.android.com/topic/libraries/support-library/index).
Expand Down Expand Up @@ -1889,26 +1888,6 @@ FirebasePlugin.isCrashlyticsCollectionEnabled(function(enabled){
});
```

### isCrashlyticsCollectionCurrentlyEnabled
Indicates whether Crashlytics collection is enabled for the current app session.

Notes:
- This value only applies to the current app session - it **does not** apply to the value set by [setCrashlyticsCollectionEnabled()](#setcrashlyticscollectionenabled) which will be applied at the start of the next app session (after the app has fully restarted).
- This value **does not** persist between app sessions - it's value is for the current session only.
- If automatic data collection was not [disabled on app startup](#disable-data-collection-on-startup), this will always return `true`.

**Parameters**:
- {function} success - callback function which will be invoked on success.
Will be passed a {boolean} indicating if collection is enabled.
- {function} error - (optional) callback function which will be passed a {string} error message as an argument

```javascript
FirebasePlugin.isCrashlyticsCollectionCurrentlyEnabled(function(enabled){
console.log("Crashlytics data collection is "+(enabled ? "enabled" : "disabled")+" for the current app session");
}, function(error){
console.error("Error getting current Crashlytics data collection state: "+error);
});
```

### setCrashlyticsUserId
Set Crashlytics user identifier.
Expand Down
11 changes: 5 additions & 6 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
<preference name="ANDROID_FIREBASE_AUTH_VERSION" default="19.3.1" />
<preference name="ANDROID_FIREBASE_INAPPMESSAGING_VERSION" default="19.0.6" />
<preference name="ANDROID_FIREBASE_FIRESTORE_VERSION" default="21.4.3" />
<preference name="ANDROID_CRASHLYTICS_VERSION" default="2.10.1" />
<preference name="ANDROID_CRASHLYTICS_NDK_VERSION" default="2.1.1" />
<preference name="ANDROID_FIREBASE_CRASHLYTICS_VERSION" default="17.0.1" />
<preference name="ANDROID_FIREBASE_CRASHLYTICS_NDK_VERSION" default="17.0.1" />
<preference name="ANDROID_GSON_VERSION" default="2.8.6" />

<framework src="com.google.android.gms:play-services-tagmanager:$ANDROID_PLAY_SERVICES_TAGMANAGER_VERSION" />
Expand All @@ -83,8 +83,8 @@
<framework src="com.google.firebase:firebase-auth:$ANDROID_FIREBASE_AUTH_VERSION" />
<framework src="com.google.firebase:firebase-inappmessaging-display:$ANDROID_FIREBASE_INAPPMESSAGING_VERSION" />
<framework src="com.google.firebase:firebase-firestore:$ANDROID_FIREBASE_FIRESTORE_VERSION" />
<framework src="com.crashlytics.sdk.android:crashlytics:$ANDROID_CRASHLYTICS_VERSION" />
<framework src="com.crashlytics.sdk.android:crashlytics-ndk:$ANDROID_CRASHLYTICS_NDK_VERSION" />
<framework src="com.google.firebase:firebase-crashlytics:$ANDROID_FIREBASE_CRASHLYTICS_VERSION" />
<framework src="com.google.firebase:firebase-crashlytics-ndk:$ANDROID_FIREBASE_CRASHLYTICS_NDK_VERSION" />
<framework src="com.google.code.gson:gson:$ANDROID_GSON_VERSION" />
</platform>

Expand Down Expand Up @@ -138,8 +138,7 @@
<pod name="Firebase/RemoteConfig" spec="6.23.0"/>
<pod name="Firebase/InAppMessaging" spec="6.23.0"/>
<pod name="Firebase/Firestore" spec="6.23.0"/>
<pod name="Fabric" spec="1.10.2"/>
<pod name="Crashlytics" spec="3.14.0"/>
<pod name="Firebase/Crashlytics" spec="6.23.0"/>
<pod name="GoogleSignIn" spec="5.0.2"/>
<pod name="GoogleTagManager" spec="7.1.2"/>
</pods>
Expand Down
4 changes: 2 additions & 2 deletions scripts/ios/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = {
xcodeProject.parseSync();

// Build the body of the script to be executed during the build phase.
var script = '"' + '\\"${PODS_ROOT}/Fabric/run\\"' + '"';
var script = '"' + '\\"${PODS_ROOT}/FirebaseCrashlytics/run\\"' + '"';

// Generate a unique ID for our new build phase.
var id = xcodeProject.generateUuid();
Expand Down Expand Up @@ -204,7 +204,7 @@ module.exports = {
googlePlistModified = true;
}
if(typeof pluginVariables['FIREBASE_CRASHLYTICS_COLLECTION_ENABLED'] !== 'undefined'){
googlePlist["FIREBASE_CRASHLYTICS_COLLECTION_ENABLED"] = (pluginVariables['FIREBASE_CRASHLYTICS_COLLECTION_ENABLED'] !== "false" ? "true" : "false") ;
googlePlist["FirebaseCrashlyticsCollectionEnabled"] = (pluginVariables['FIREBASE_CRASHLYTICS_COLLECTION_ENABLED'] !== "false" ? "true" : "false") ;
googlePlistModified = true;
}
if(typeof pluginVariables['IOS_SHOULD_ESTABLISH_DIRECT_CHANNEL'] !== 'undefined'){
Expand Down
47 changes: 15 additions & 32 deletions src/android/FirebasePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import android.util.Base64;
import android.util.Log;

import com.crashlytics.android.Crashlytics;
import com.google.firebase.crashlytics.FirebaseCrashlytics;

import com.google.android.gms.auth.api.Auth;
import com.google.android.gms.auth.api.signin.GoogleSignIn;
Expand Down Expand Up @@ -62,7 +62,6 @@
import com.google.firebase.perf.FirebasePerformance;
import com.google.firebase.perf.metrics.Trace;

import io.fabric.sdk.android.Fabric;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface;
Expand Down Expand Up @@ -99,14 +98,14 @@ public class FirebasePlugin extends CordovaPlugin {

protected static FirebasePlugin instance = null;
private FirebaseAnalytics mFirebaseAnalytics;
private FirebaseCrashlytics firebaseCrashlytics;
private FirebaseFirestore firestore;
private Gson gson;
private FirebaseAuth.AuthStateListener authStateListener;
private boolean authStateChangeListenerInitialized = false;
private static CordovaInterface cordovaInterface = null;
protected static Context applicationContext = null;
private static Activity cordovaActivity = null;
private boolean isCrashlyticsEnabled = false;

protected static final String TAG = "FirebasePlugin";
protected static final String JS_GLOBAL_NAMESPACE = "FirebasePlugin.";
Expand Down Expand Up @@ -138,18 +137,13 @@ protected void pluginInitialize() {
applicationContext = cordovaActivity.getApplicationContext();
final Bundle extras = cordovaActivity.getIntent().getExtras();
FirebasePlugin.cordovaInterface = this.cordova;
firebaseCrashlytics = FirebaseCrashlytics.getInstance();
this.cordova.getThreadPool().execute(new Runnable() {
public void run() {
try {
Log.d(TAG, "Starting Firebase plugin");

if(!getMetaDataFromManifest(CRASHLYTICS_COLLECTION_ENABLED)){
isCrashlyticsEnabled = getPreference(CRASHLYTICS_COLLECTION_ENABLED);
if(isCrashlyticsEnabled){
Fabric.with(applicationContext, new Crashlytics());
}
}else{
isCrashlyticsEnabled = true;
setPreference(CRASHLYTICS_COLLECTION_ENABLED, true);
}

Expand Down Expand Up @@ -354,9 +348,6 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
} else if (action.equals("isCrashlyticsCollectionEnabled")) {
this.isCrashlyticsCollectionEnabled(callbackContext);
return true;
} else if (action.equals("isCrashlyticsCollectionCurrentlyEnabled")) {
this.isCrashlyticsCollectionCurrentlyEnabled(callbackContext);
return true;
} else if (action.equals("clearAllNotifications")) {
this.clearAllNotifications(callbackContext);
return true;
Expand Down Expand Up @@ -733,7 +724,7 @@ private void logError(final CallbackContext callbackContext, final JSONArray arg
cordova.getThreadPool().execute(new Runnable() {
public void run() {
try {
if(isCrashlyticsEnabled) {
if(isCrashlyticsEnabled()) {
// We can optionally be passed a stack trace generated by stacktrace.js.
if (args.length() == 2) {
JSONArray stackTrace = args.getJSONArray(1);
Expand Down Expand Up @@ -771,7 +762,7 @@ public void run() {
private void logMessage(final JSONArray data,
final CallbackContext callbackContext) {

if(isCrashlyticsEnabled){
if(isCrashlyticsEnabled()){
String message = data.optString(0);
logMessageToCrashlytics(message);
callbackContext.success();
Expand All @@ -796,8 +787,8 @@ private void setCrashlyticsUserId(final CallbackContext callbackContext, final S
cordovaActivity.runOnUiThread(new Runnable() {
public void run() {
try {
if(isCrashlyticsEnabled){
Crashlytics.setUserIdentifier(userId);
if(isCrashlyticsEnabled()){
firebaseCrashlytics.setUserId(userId);
callbackContext.success();
}else{
callbackContext.error("Cannot set Crashlytics user ID - Crashlytics collection is disabled");
Expand Down Expand Up @@ -1765,6 +1756,7 @@ private void setCrashlyticsCollectionEnabled(final CallbackContext callbackConte
cordova.getThreadPool().execute(new Runnable() {
public void run() {
try {
firebaseCrashlytics.setCrashlyticsCollectionEnabled(enabled);
setPreference(CRASHLYTICS_COLLECTION_ENABLED, enabled);
callbackContext.success();
} catch (Exception e) {
Expand All @@ -1779,7 +1771,7 @@ private void isCrashlyticsCollectionEnabled(final CallbackContext callbackContex
cordova.getThreadPool().execute(new Runnable() {
public void run() {
try {
callbackContext.success(getPreference(CRASHLYTICS_COLLECTION_ENABLED) ? 1 : 0);
callbackContext.success(isCrashlyticsEnabled() ? 1 : 0);
} catch (Exception e) {
handleExceptionWithContext(e, callbackContext);
e.printStackTrace();
Expand All @@ -1788,17 +1780,8 @@ public void run() {
});
}

private void isCrashlyticsCollectionCurrentlyEnabled(final CallbackContext callbackContext) {
cordova.getThreadPool().execute(new Runnable() {
public void run() {
try {
callbackContext.success(isCrashlyticsEnabled ? 1 : 0);
} catch (Exception e) {
handleExceptionWithContext(e, callbackContext);
e.printStackTrace();
}
}
});
private boolean isCrashlyticsEnabled(){
return getPreference(CRASHLYTICS_COLLECTION_ENABLED);
}

public void clearAllNotifications(final CallbackContext callbackContext) {
Expand Down Expand Up @@ -2483,9 +2466,9 @@ private JSONObject mapToJsonObject(Map<String, Object> map) throws JSONException
}

private void logMessageToCrashlytics(String message){
if(isCrashlyticsEnabled){
if(isCrashlyticsEnabled()){
try{
Crashlytics.log(message);
firebaseCrashlytics.log(message);
}catch (Exception e){
Log.e(TAG, e.getMessage());
}
Expand All @@ -2495,9 +2478,9 @@ private void logMessageToCrashlytics(String message){
}

private void logExceptionToCrashlytics(Exception exception){
if(isCrashlyticsEnabled){
if(isCrashlyticsEnabled()){
try{
Crashlytics.logException(exception);
firebaseCrashlytics.recordException(exception);
}catch (Exception e){
Log.e(TAG, e.getMessage());
}
Expand Down
2 changes: 1 addition & 1 deletion src/android/FirebasePluginMessagingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import android.content.ContentResolver;
import android.graphics.Color;

import com.crashlytics.android.Crashlytics;
import com.google.firebase.crashlytics.FirebaseCrashlytics;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;

Expand Down
18 changes: 10 additions & 8 deletions src/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
buildscript {
repositories {
google()
maven {
url "https://maven.fabric.io/public"
}
mavenCentral()
jcenter()
}
dependencies {
classpath "io.fabric.tools:gradle:1.30.0"
classpath 'com.android.tools.build:gradle:3.4.1'
classpath 'com.google.gms:google-services:4.2.0'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.1.1'
}
}
repositories {
Expand All @@ -35,11 +32,16 @@ cdvPluginPostBuildExtras.add({
}
// Use class instead of id (string) to be able to apply plugin from non-root gradle file

apply plugin: com.crashlytics.tools.gradle.CrashlyticsPlugin
apply plugin: com.google.firebase.crashlytics.buildtools.gradle.CrashlyticsPlugin

// Enable Crashlytics NDK reporting
crashlytics {
enableNdk true
android {
buildTypes {
release {
firebaseCrashlytics {
nativeSymbolUploadEnabled true
}
}
}
}
})

Expand Down
6 changes: 1 addition & 5 deletions src/ios/AppDelegate+FirebasePlugin.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#import "AppDelegate+FirebasePlugin.h"
#import "FirebasePlugin.h"
#import "Firebase.h"
#import <Fabric/Fabric.h>
#import <objc/runtime.h>


Expand Down Expand Up @@ -83,10 +82,7 @@ - (BOOL)application:(UIApplication *)application swizzledDidFinishLaunchingWithO
isFirebaseInitializedWithPlist = true;
}

// Initialise Crashlytics
if(isFirebaseInitializedWithPlist && [FirebasePlugin.firebasePlugin _shouldEnableCrashlytics]){
[Fabric with:@[[Crashlytics class]]];
}


shouldEstablishDirectChannel = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"shouldEstablishDirectChannel"] boolValue];

Expand Down
1 change: 0 additions & 1 deletion src/ios/FirebasePlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
// Crashlytics
- (void)setCrashlyticsCollectionEnabled:(CDVInvokedUrlCommand*)command;
- (void)isCrashlyticsCollectionEnabled:(CDVInvokedUrlCommand*)command;
- (void)isCrashlyticsCollectionCurrentlyEnabled:(CDVInvokedUrlCommand*)command;
- (void)logError:(CDVInvokedUrlCommand*)command;
- (void)logMessage:(CDVInvokedUrlCommand*)command;
- (void)sendCrash:(CDVInvokedUrlCommand*)command;
Expand Down
Loading

0 comments on commit d6c60a2

Please sign in to comment.