Skip to content

Commit 03bf9aa

Browse files
authored
[Feature] - Crash Reporting (#127)
* crash reporting * crash reporting * updates readme * updates readme * Add manual crash reporting * Add enable API * Add unit test for new API * ci * Add unit test for crash reporting API * Update changelog * ci * revert pod file changes * Update native iOS API * revert runner changes * Pushing iOS custom branch for CI to pass, will be reversed once merged * Prefixing Log statemenet * Rename `setCurrentPlatform` args * Adds android custom branch * fixing incorrect platform * Add native android SDK * remove custom iOS snapshot * Bump to version 9.1.6 * update readme
1 parent 49c6074 commit 03bf9aa

File tree

20 files changed

+426
-119
lines changed

20 files changed

+426
-119
lines changed

.circleci/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ jobs:
104104
- run:
105105
name: Flutter build
106106
command: cd ..; flutter build aot
107+
- run:
108+
name: Update CocoaPods
109+
command: pod update
107110
- run:
108111
name: Install CocoaPods
109112
command: pod install --repo-update

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
## Master
1+
## v9.1.6 (2020-07-13)
22

3+
* Adds CrashReporting
34
* Adds setShakingThresholdForiPhone, setShakingThresholdForiPad and setShakingThresholdForAndroid APIs
45
* Added Proguard rules to protect Flutter bridge class and method names from getting obfuscated when the minifyEnabled flag is set to true.
56

6-
77
## v9.1.0 (2020-03-19)
88

99
* Bump Native SDKs to v9.1

README.md

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@ A Flutter plugin for [Instabug](https://instabug.com/).
99
| Feature | Status |
1010
|:---------------------------------------------------------:|:-------:|
1111
| [Bug Reporting](https://instabug.com/bug-reporting) ||
12-
| [Crash Reporting](https://instabug.com/crash-reporting) | |
12+
| [Crash Reporting](https://instabug.com/crash-reporting) | |
1313
| [In-App Chat](https://instabug.com/in-app-chat) ||
1414
| [In-App Surveys](https://instabug.com/in-app-surveys) ||
1515
| [Feature Requests](https://instabug.com/feature-requests) ||
1616

1717
* ✅ Stable
1818
* ⚙️ Under active development
19-
* ⚠ Not available yet
2019

2120
## Integration
2221

@@ -27,7 +26,7 @@ A Flutter plugin for [Instabug](https://instabug.com/).
2726

2827
```yaml
2928
dependencies:
30-
instabug_flutter:
29+
instabug_flutter:
3130
```
3231
3332
2. Install the package by running the following command.
@@ -81,21 +80,43 @@ invocationEvents.add(InstabugFlutterPlugin.INVOCATION_EVENT_SHAKE);
8180
new InstabugFlutterPlugin().start(CustomFlutterApplication.this, "APP_TOKEN", invocationEvents);
8281
```
8382

84-
## Microphone and Photo Library Usage Description (iOS Only)
83+
## Crash reporting
8584

86-
Instabug needs access to the microphone and photo library to be able to let users add audio and video attachments. Starting from iOS 10, apps that don’t provide a usage description for those 2 permissions would be rejected when submitted to the App Store.
85+
Instabug automatically captures every crash of your app and sends relevant details to the crashes page of your dashboard. Crashes are reported only when the app is running in release mode
8786

88-
For your app not to be rejected, you’ll need to add the following 2 keys to your app’s info.plist file with text explaining to the user why those permissions are needed:
87+
1. To start using Crash reporting, import the following into your `main.dart`.
8988

90-
* `NSMicrophoneUsageDescription`
91-
* `NSPhotoLibraryUsageDescription`
92-
93-
If your app doesn’t already access the microphone or photo library, we recommend using a usage description like:
89+
```dart
90+
import 'package:instabug_flutter/CrashReporting.dart';
91+
```
9492

95-
* "`<app name>` needs access to the microphone to be able to attach voice notes."
96-
* "`<app name>` needs access to your photo library for you to be able to attach images."
93+
2. Replace `void main() => runApp(MyApp());` with the following snippet:
94+
```dart
95+
void main() async {
96+
FlutterError.onError = (FlutterErrorDetails details) {
97+
Zone.current.handleUncaughtError(details.exception, details.stack);
98+
};
99+
runZoned<Future<void>>(() async {
100+
runApp(MyApp());
101+
}, onError: (dynamic error, StackTrace stackTrace) {
102+
CrashReporting.reportCrash(error, stackTrace);
103+
});
104+
}
105+
```
97106

98-
**The permission alert for accessing the microphone/photo library will NOT appear unless users attempt to attach a voice note/photo while using Instabug.**
107+
With Flutter 1.17 use this snipped instead:
108+
```dart
109+
void main() async {
110+
FlutterError.onError = (FlutterErrorDetails details) {
111+
Zone.current.handleUncaughtError(details.exception, details.stack);
112+
};
113+
runZonedGuarded<Future<void>>(() async {
114+
runApp(CrashyApp());
115+
}, (Object error, StackTrace stackTrace) {
116+
CrashReporting.reportCrash(error, stackTrace);
117+
});
118+
}
119+
```
99120

100121
## Network Logging
101122
You can choose to attach all your network requests to the reports being sent to the dashboard. To enable the feature when using the `dart:io` package `HttpClient`, use the custom Instabug client:
@@ -111,4 +132,20 @@ client.getUrl(Uri.parse(URL)).then((request) async {
111132
});
112133
```
113134

114-
We also support the packages `http` and `dio`. For details on how to enable network logging for these external packages, refer to the [Instabug Dart Http Adapter](https://github.com/Instabug/Instabug-Dart-http-Adapter) and the [Instabug Dio Interceptor](https://github.com/Instabug/Instabug-Dio-Interceptor) repositories.
135+
We also support the packages `http` and `dio`. For details on how to enable network logging for these external packages, refer to the [Instabug Dart Http Adapter](https://github.com/Instabug/Instabug-Dart-http-Adapter) and the [Instabug Dio Interceptor](https://github.com/Instabug/Instabug-Dio-Interceptor) repositories.
136+
137+
## Microphone and Photo Library Usage Description (iOS Only)
138+
139+
Instabug needs access to the microphone and photo library to be able to let users add audio and video attachments. Starting from iOS 10, apps that don’t provide a usage description for those 2 permissions would be rejected when submitted to the App Store.
140+
141+
For your app not to be rejected, you’ll need to add the following 2 keys to your app’s info.plist file with text explaining to the user why those permissions are needed:
142+
143+
* `NSMicrophoneUsageDescription`
144+
* `NSPhotoLibraryUsageDescription`
145+
146+
If your app doesn’t already access the microphone or photo library, we recommend using a usage description like:
147+
148+
* "`<app name>` needs access to the microphone to be able to attach voice notes."
149+
* "`<app name>` needs access to your photo library for you to be able to attach images."
150+
151+
**The permission alert for accessing the microphone/photo library will NOT appear unless users attempt to attach a voice note/photo while using Instabug.**

android/src/main/java/com/instabug/instabugflutter/InstabugFlutterPlugin.java

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.instabug.bug.invocation.Option;
1212
import com.instabug.chat.Chats;
1313
import com.instabug.chat.Replies;
14+
import com.instabug.crash.CrashReporting;
1415
import com.instabug.featuresrequest.FeatureRequests;
1516
import com.instabug.library.Feature;
1617
import com.instabug.library.Instabug;
@@ -38,6 +39,7 @@
3839
import java.util.ArrayList;
3940
import java.util.HashMap;
4041
import java.util.Iterator;
42+
import java.util.LinkedHashMap;
4143
import java.util.List;
4244
import java.util.Locale;
4345
import java.util.Map;
@@ -897,12 +899,53 @@ public void networkLog(HashMap<String, Object> jsonObject) throws JSONException
897899
}
898900

899901
/**
900-
* Reports that the screen has been changed (Repro Steps) the screen sent to
901-
* this method will be the 'current view' on the dashboard
902+
* Enables and disables automatic crash reporting.
903+
*
904+
* @param {boolean} isEnabled
905+
*/
906+
public void setCrashReportingEnabled(final boolean isEnabled) {
907+
new Handler(Looper.getMainLooper()).post(new Runnable() {
908+
@Override
909+
public void run() {
910+
if (isEnabled) {
911+
CrashReporting.setState(Feature.State.ENABLED);
912+
} else {
913+
CrashReporting.setState(Feature.State.DISABLED);
914+
}
915+
}
916+
});
917+
}
918+
919+
public void sendJSCrashByReflection(final String map, final boolean isHandled) {
920+
new Handler(Looper.getMainLooper()).post(new Runnable() {
921+
@Override
922+
public void run() {
923+
try {
924+
final JSONObject exceptionObject = new JSONObject(map);
925+
Method method = getMethod(Class.forName("com.instabug.crash.CrashReporting"), "reportException",
926+
JSONObject.class, boolean.class);
927+
if (method != null) {
928+
method.invoke(null, exceptionObject, isHandled);
929+
Log.e("IBG-Flutter", exceptionObject.toString());
930+
}
931+
} catch (Exception e) {
932+
e.printStackTrace();
933+
}
934+
}
935+
});
936+
}
937+
938+
/*
939+
*
940+
* Reports that the screen has been
941+
*
942+
* changed (Repro Steps) the screen sent to this method will be the 'current
943+
* view' on the dashboard
902944
*
903945
* @param screenName string containing the screen name
904946
*
905947
*/
948+
906949
public void reportScreenChange(String screenName) {
907950
try {
908951
Method method = getMethod(Class.forName("com.instabug.library.Instabug"), "reportScreenChange",
@@ -930,10 +973,10 @@ public void setReproStepsMode(String reproStepsMode) {
930973
}
931974

932975
/**
933-
* Sets the threshold value of the shake gesture for android devices.
934-
* Default for android is an integer value equals 350.
935-
* you could increase the shaking difficulty level by
936-
* increasing the `350` value and vice versa
976+
* Sets the threshold value of the shake gesture for android devices. Default
977+
* for android is an integer value equals 350. you could increase the shaking
978+
* difficulty level by increasing the `350` value and vice versa
979+
*
937980
* @param androidThreshold Threshold for android devices.
938981
*/
939982
public void setShakingThresholdForAndroid(int androidThreshold) {

example/android/app/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ android {
3939
versionCode flutterVersionCode.toInteger()
4040
versionName flutterVersionName
4141
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
42+
multiDexEnabled true
4243
}
4344

4445
buildTypes {
@@ -59,6 +60,7 @@ flutter {
5960

6061
dependencies {
6162
testImplementation 'junit:junit:4.12'
63+
implementation 'com.android.support:multidex:1.0.3'
6264
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
6365
androidTestImplementation 'androidx.test:rules:1.1.1'
6466
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.instabug.instabugflutterexample">
3+
<!-- Flutter needs it to communicate with the running application
4+
to allow setting breakpoints, to provide hot reload, etc.
5+
-->
6+
<uses-permission android:name="android.permission.INTERNET"/>
7+
</manifest>

example/android/app/src/main/java/com/instabug/instabugflutterexample/CustomFlutterApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public void onCreate() {
1212
ArrayList<String> invocation_events = new ArrayList<>();
1313
invocation_events.add(InstabugFlutterPlugin.INVOCATION_EVENT_FLOATING_BUTTON);
1414
InstabugFlutterPlugin instabug = new InstabugFlutterPlugin();
15-
instabug.start(CustomFlutterApplication.this, "efa41f402620b5654f2af2b86e387029", invocation_events);
15+
instabug.start(CustomFlutterApplication.this, "2d355f559ea67051a56fce82603f8e41", invocation_events);
1616
instabug.setWelcomeMessageMode("WelcomeMessageMode.disabled");
1717
}
1818
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.instabug.instabugflutterexample">
3+
<!-- Flutter needs it to communicate with the running application
4+
to allow setting breakpoints, to provide hot reload, etc.
5+
-->
6+
<uses-permission android:name="android.permission.INTERNET"/>
7+
</manifest>

example/ios/Flutter/Flutter.podspec

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# NOTE: This podspec is NOT to be published. It is only used as a local source!
3+
#
4+
5+
Pod::Spec.new do |s|
6+
s.name = 'Flutter'
7+
s.version = '1.0.0'
8+
s.summary = 'High-performance, high-fidelity mobile apps.'
9+
s.description = <<-DESC
10+
Flutter provides an easy and productive way to build and deploy high-performance mobile apps for Android and iOS.
11+
DESC
12+
s.homepage = 'https://flutter.io'
13+
s.license = { :type => 'MIT' }
14+
s.author = { 'Flutter Dev Team' => '[email protected]' }
15+
s.source = { :git => 'https://github.com/flutter/engine', :tag => s.version.to_s }
16+
s.ios.deployment_target = '8.0'
17+
s.vendored_frameworks = 'Flutter.framework'
18+
end

example/ios/Podfile

100755100644
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ def parse_KV_file(file, separator='=')
1717
pods_ary = []
1818
skip_line_start_symbols = ["#", "/"]
1919
File.foreach(file_abs_path) { |line|
20-
next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
21-
plugin = line.split(pattern=separator)
22-
if plugin.length == 2
23-
podname = plugin[0].strip()
24-
path = plugin[1].strip()
25-
podpath = File.expand_path("#{path}", file_abs_path)
26-
pods_ary.push({:name => podname, :path => podpath});
20+
next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
21+
plugin = line.split(pattern=separator)
22+
if plugin.length == 2
23+
podname = plugin[0].strip()
24+
path = plugin[1].strip()
25+
podpath = File.expand_path("#{path}", file_abs_path)
26+
pods_ary.push({:name => podname, :path => podpath});
2727
else
28-
puts "Invalid plugin specification: #{line}"
29-
end
28+
puts "Invalid plugin specification: #{line}"
29+
end
3030
}
3131
return pods_ary
3232
end
@@ -36,7 +36,7 @@ target 'Runner' do
3636
# referring to absolute paths on developers' machines.
3737
system('rm -rf .symlinks')
3838
system('mkdir -p .symlinks/plugins')
39-
39+
4040
# Flutter Pods
4141
generated_xcode_build_settings = parse_KV_file('./Flutter/Generated.xcconfig')
4242
if generated_xcode_build_settings.empty?
@@ -49,7 +49,7 @@ target 'Runner' do
4949
pod 'Flutter', :path => File.join(symlink, File.basename(p[:path]))
5050
end
5151
}
52-
52+
5353
# Plugin Pods
5454
plugin_pods = parse_KV_file('../.flutter-plugins')
5555
plugin_pods.map { |p|
@@ -95,4 +95,4 @@ post_install do |installer|
9595
end
9696
end
9797

98-
pod 'OCMock', '~> 3.4'
98+
pod 'OCMock', '~> 3.4'

example/ios/Podfile.lock

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
PODS:
2+
- Flutter (1.0.0)
3+
- Instabug (9.1.4)
4+
- instabug_flutter (0.0.1):
5+
- Flutter
6+
- Instabug (= 9.1.4)
7+
- OCMock (3.6)
8+
9+
DEPENDENCIES:
10+
- Flutter (from `.symlinks/flutter/ios`)
11+
- instabug_flutter (from `.symlinks/plugins/instabug_flutter/ios`)
12+
- OCMock (~> 3.4)
13+
14+
SPEC REPOS:
15+
trunk:
16+
- Instabug
17+
- OCMock
18+
19+
EXTERNAL SOURCES:
20+
Flutter:
21+
:path: ".symlinks/flutter/ios"
22+
instabug_flutter:
23+
:path: ".symlinks/plugins/instabug_flutter/ios"
24+
25+
SPEC CHECKSUMS:
26+
Flutter: 0e3d915762c693b495b44d77113d4970485de6ec
27+
Instabug: 6d8d38c329b8ae0a88bba4d148280e24bc0cf000
28+
instabug_flutter: 904f8ae866249364e68e2d0ca05fc903f2fb7573
29+
OCMock: 5ea90566be239f179ba766fd9fbae5885040b992
30+
31+
PODFILE CHECKSUM: 8a47551d4cb50d1be73b4b5bed8629d9a9468757
32+
33+
COCOAPODS: 1.9.1

0 commit comments

Comments
 (0)