Skip to content

Commit b22a659

Browse files
committed
[crashlytics] Migrate to new Crashlytics SDK
1 parent bdb95fc commit b22a659

File tree

12 files changed

+26
-120
lines changed

12 files changed

+26
-120
lines changed

packages/firebase_crashlytics/CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## 0.2.0
2+
3+
* **Breaking**: Migration to the new Firebase Crashlytics SDK. Follow the [migration guide](https://firebase.google.com/docs/crashlytics/upgrade-sdk?platform=android) to update your app.
4+
* **Breaking**: the following methods have been removed:
5+
* `setUserEmail`
6+
* `setUserName`
7+
* `getVersion`
8+
* `isDebuggable`
9+
110
## 0.1.3+3
211

312
* Fix for missing UserAgent.h compilation failures.

packages/firebase_crashlytics/android/build.gradle

+1-4
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ rootProject.allprojects {
1616
repositories {
1717
google()
1818
jcenter()
19-
maven {
20-
url 'https://maven.fabric.io/public'
21-
}
2219
}
2320
}
2421

@@ -37,7 +34,7 @@ android {
3734
}
3835

3936
dependencies {
40-
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.9'
37+
implementation 'com.google.firebase:firebase-crashlytics:17.0.0-beta03'
4138
implementation 'com.google.firebase:firebase-common:16.1.0'
4239
implementation 'androidx.annotation:annotation:1.1.0'
4340
}

packages/firebase_crashlytics/android/src/main/java/io/flutter/plugins/firebase/crashlytics/firebasecrashlytics/FirebaseCrashlyticsPlugin.java

+12-27
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
import android.content.Context;
88
import android.util.Log;
9-
import com.crashlytics.android.Crashlytics;
10-
import io.fabric.sdk.android.Fabric;
9+
import com.google.firebase.crashlytics.FirebaseCrashlytics;
1110
import io.flutter.embedding.engine.plugins.FlutterPlugin;
1211
import io.flutter.plugin.common.BinaryMessenger;
1312
import io.flutter.plugin.common.MethodCall;
@@ -42,11 +41,6 @@ private static MethodChannel setup(BinaryMessenger binaryMessenger, Context cont
4241
final MethodChannel channel =
4342
new MethodChannel(binaryMessenger, "plugins.flutter.io/firebase_crashlytics");
4443
channel.setMethodCallHandler(new FirebaseCrashlyticsPlugin());
45-
46-
if (!Fabric.isInitialized()) {
47-
Fabric.with(context, new Crashlytics());
48-
}
49-
5044
return channel;
5145
}
5246

@@ -57,28 +51,29 @@ public static void registerWith(Registrar registrar) {
5751

5852
@Override
5953
public void onMethodCall(MethodCall call, Result result) {
54+
final FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
6055
if (call.method.equals("Crashlytics#onError")) {
6156
// Add logs.
6257
List<String> logs = call.argument("logs");
6358
for (String log : logs) {
64-
Crashlytics.log(log);
59+
crashlytics.log(log);
6560
}
6661

6762
// Set keys.
6863
List<Map<String, Object>> keys = call.argument("keys");
6964
for (Map<String, Object> key : keys) {
7065
switch ((String) key.get("type")) {
7166
case "int":
72-
Crashlytics.setInt((String) key.get("key"), (int) key.get("value"));
67+
crashlytics.setCustomKey((String) key.get("key"), (int) key.get("value"));
7368
break;
7469
case "double":
75-
Crashlytics.setDouble((String) key.get("key"), (double) key.get("value"));
70+
crashlytics.setCustomKey((String) key.get("key"), (double) key.get("value"));
7671
break;
7772
case "string":
78-
Crashlytics.setString((String) key.get("key"), (String) key.get("value"));
73+
crashlytics.setCustomKey((String) key.get("key"), (String) key.get("value"));
7974
break;
8075
case "boolean":
81-
Crashlytics.setBool((String) key.get("key"), (boolean) key.get("value"));
76+
crashlytics.setCustomKey((String) key.get("key"), (boolean) key.get("value"));
8277
break;
8378
}
8479
}
@@ -96,30 +91,20 @@ public void onMethodCall(MethodCall call, Result result) {
9691
}
9792
exception.setStackTrace(elements.toArray(new StackTraceElement[elements.size()]));
9893

99-
Crashlytics.setString("exception", (String) call.argument("exception"));
94+
crashlytics.setCustomKey("exception", (String) call.argument("exception"));
10095

10196
// Set a "reason" (to match iOS) to show where the exception was thrown.
10297
final String context = call.argument("context");
103-
if (context != null) Crashlytics.setString("reason", "thrown " + context);
98+
if (context != null) crashlytics.setCustomKey("reason", "thrown " + context);
10499

105100
// Log information.
106101
final String information = call.argument("information");
107-
if (information != null && !information.isEmpty()) Crashlytics.log(information);
102+
if (information != null && !information.isEmpty()) crashlytics.log(information);
108103

109-
Crashlytics.logException(exception);
104+
crashlytics.recordException(exception);
110105
result.success("Error reported to Crashlytics.");
111-
} else if (call.method.equals("Crashlytics#isDebuggable")) {
112-
result.success(Fabric.isDebuggable());
113-
} else if (call.method.equals("Crashlytics#getVersion")) {
114-
result.success(Crashlytics.getInstance().getVersion());
115-
} else if (call.method.equals("Crashlytics#setUserEmail")) {
116-
Crashlytics.setUserEmail((String) call.argument("email"));
117-
result.success(null);
118106
} else if (call.method.equals("Crashlytics#setUserIdentifier")) {
119-
Crashlytics.setUserIdentifier((String) call.argument("identifier"));
120-
result.success(null);
121-
} else if (call.method.equals("Crashlytics#setUserName")) {
122-
Crashlytics.setUserName((String) call.argument("name"));
107+
crashlytics.setUserId((String) call.argument("identifier"));
123108
result.success(null);
124109
} else {
125110
result.notImplemented();

packages/firebase_crashlytics/example/android/app/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,5 @@ dependencies {
6464
implementation "android.arch.lifecycle:extensions:1.1.1"
6565
}
6666

67-
apply plugin: 'io.fabric'
6867
apply plugin: 'com.google.gms.google-services'
68+
apply plugin: 'com.google.firebase.crashlytics'

packages/firebase_crashlytics/example/android/app/src/androidTest/java/io/flutter/plugins/firebase/crashlytics/firebasecrashlytics/EmbeddingV1ActivityTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
package io.flutter.plugins.firebase.crashlytics.firebasecrashlytics;
32

43
import androidx.test.rule.ActivityTestRule;

packages/firebase_crashlytics/example/android/app/src/main/java/io/flutter/plugins/firebase/crashlytics/firebasecrashlyticsexample/EmbeddingV1Activity.java

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
package io.flutter.plugins.firebase.crashlytics.firebasecrashlyticsexample;
32

43
import android.os.Bundle;

packages/firebase_crashlytics/example/android/build.gradle

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@ buildscript {
22
repositories {
33
google()
44
jcenter()
5-
maven {
6-
url 'https://maven.fabric.io/public'
7-
}
85
}
96

107
dependencies {
118
classpath 'com.android.tools.build:gradle:3.3.2'
129
classpath 'com.google.gms:google-services:4.3.0'
13-
classpath 'io.fabric.tools:gradle:1.26.1'
10+
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.0.0-beta03'
1411
}
1512
}
1613

packages/firebase_crashlytics/example/test_driver/crashlytics.dart

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ void main() {
1717
test('recordFlutterError', () async {
1818
// This is currently only testing that we can log errors without crashing.
1919
final Crashlytics crashlytics = Crashlytics.instance;
20-
await crashlytics.setUserName('testing');
2120
await crashlytics.setUserIdentifier('hello');
2221
crashlytics.setBool('testBool', true);
2322
crashlytics.setInt('testInt', 42);

packages/firebase_crashlytics/lib/src/firebase_crashlytics.dart

-29
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,6 @@ class Crashlytics {
5454
throw StateError('Error thrown by Crashlytics plugin');
5555
}
5656

57-
/// Reports the global value for debug mode.
58-
/// TODO(kroikie): Clarify what this means in context of both Android and iOS.
59-
Future<bool> isDebuggable() async {
60-
final bool result =
61-
await channel.invokeMethod<bool>('Crashlytics#isDebuggable');
62-
return result;
63-
}
64-
65-
/// Returns Crashlytics SDK version.
66-
Future<String> getVersion() async {
67-
final String result =
68-
await channel.invokeMethod<String>('Crashlytics#getVersion');
69-
return result;
70-
}
71-
7257
/// Add text logging that will be sent with your next report. `msg` will be
7358
/// printed to the console when in debug mode. Each report has a rolling max
7459
/// of 64k of logs, older logs are removed to allow newer logs to fit within
@@ -110,27 +95,13 @@ class Crashlytics {
11095
_setValue(key, value);
11196
}
11297

113-
/// Optionally set a end-user's name or username for display within the
114-
/// Crashlytics UI. Please be mindful of end-user's privacy.
115-
Future<void> setUserEmail(String email) async {
116-
await channel.invokeMethod<void>(
117-
'Crashlytics#setUserEmail', <String, dynamic>{'email': email});
118-
}
119-
12098
/// Specify a user identifier which will be visible in the Crashlytics UI.
12199
/// Please be mindful of end-user's privacy.
122100
Future<void> setUserIdentifier(String identifier) async {
123101
await channel.invokeMethod<void>('Crashlytics#setUserIdentifier',
124102
<String, dynamic>{'identifier': identifier});
125103
}
126104

127-
/// Specify a user name which will be visible in the Crashlytics UI. Please
128-
/// be mindful of end-user's privacy.
129-
Future<void> setUserName(String name) async {
130-
await channel.invokeMethod<void>(
131-
'Crashlytics#setUserName', <String, dynamic>{'name': name});
132-
}
133-
134105
List<Map<String, dynamic>> _prepareKeys() {
135106
final List<Map<String, dynamic>> crashlyticsKeys = <Map<String, dynamic>>[];
136107
for (String key in _keys.keys) {

packages/firebase_crashlytics/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: firebase_crashlytics
22
description:
33
Flutter plugin for Firebase Crashlytics. It reports uncaught errors to the
44
Firebase console.
5-
version: 0.1.3+3
5+
version: 0.2.0
66
homepage: https://github.com/FirebaseExtended/flutterfire/tree/master/packages/firebase_crashlytics
77

88
environment:
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
1-
import 'package:flutter_test/flutter_test.dart';
21
import 'package:e2e/e2e.dart';
3-
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
42

53
void main() {
64
E2EWidgetsFlutterBinding.ensureInitialized();
7-
8-
testWidgets('get version', (WidgetTester tester) async {
9-
final String version = await Crashlytics.instance.getVersion();
10-
expect(version, isNotNull);
11-
});
125
}

packages/firebase_crashlytics/test/firebase_crashlytics_test.dart

+1-44
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import 'package:flutter_test/flutter_test.dart';
1212
void main() {
1313
TestWidgetsFlutterBinding.ensureInitialized();
1414

15-
group('$Crashlytics', () {
15+
group('Crashlytics', () {
1616
final List<MethodCall> log = <MethodCall>[];
1717

1818
final Crashlytics crashlytics = Crashlytics.instance;
@@ -24,16 +24,8 @@ void main() {
2424
switch (methodCall.method) {
2525
case 'Crashlytics#onError':
2626
return 'Error reported to Crashlytics.';
27-
case 'Crashlytics#isDebuggable':
28-
return true;
29-
case 'Crashlytics#setUserEmail':
30-
return true;
3127
case 'Crashlytics#setUserIdentifier':
3228
return true;
33-
case 'Crashlytics#setUserName':
34-
return true;
35-
case 'Crashlytics#getVersion':
36-
return '0.0.0+1';
3729
default:
3830
return false;
3931
}
@@ -103,37 +95,10 @@ void main() {
10395
expect(log[0].arguments['keys'][3]['type'], 'string');
10496
});
10597

106-
test('isDebuggable', () async {
107-
expect(await crashlytics.isDebuggable(), true);
108-
expect(
109-
log,
110-
<Matcher>[
111-
isMethodCall(
112-
'Crashlytics#isDebuggable',
113-
arguments: null,
114-
)
115-
],
116-
);
117-
});
118-
11998
test('crash', () {
12099
expect(() => crashlytics.crash(), throwsStateError);
121100
});
122101

123-
test('getVersion', () async {
124-
await crashlytics.getVersion();
125-
expect(log,
126-
<Matcher>[isMethodCall('Crashlytics#getVersion', arguments: null)]);
127-
});
128-
129-
test('setUserEmail', () async {
130-
await crashlytics.setUserEmail('foo');
131-
expect(log, <Matcher>[
132-
isMethodCall('Crashlytics#setUserEmail',
133-
arguments: <String, dynamic>{'email': 'foo'})
134-
]);
135-
});
136-
137102
test('setUserIdentifier', () async {
138103
await crashlytics.setUserIdentifier('foo');
139104
expect(log, <Matcher>[
@@ -142,14 +107,6 @@ void main() {
142107
]);
143108
});
144109

145-
test('setUserName', () async {
146-
await crashlytics.setUserName('foo');
147-
expect(log, <Matcher>[
148-
isMethodCall('Crashlytics#setUserName',
149-
arguments: <String, dynamic>{'name': 'foo'})
150-
]);
151-
});
152-
153110
test('getStackTraceElements with character index', () async {
154111
final List<String> lines = <String>[
155112
'package:flutter/src/widgets/framework.dart 3825:27 StatefulElement.build'

0 commit comments

Comments
 (0)