Skip to content

Commit 37f8dbc

Browse files
authored
[MOB-8388] Start SDK from Dart only (#223)
* Start SDK from Dart only * Update Changelog * Update README * Update `Instabug.start` unit test
1 parent 48d9c3e commit 37f8dbc

File tree

7 files changed

+39
-50
lines changed

7 files changed

+39
-50
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## master
2+
3+
* Supports starting SDK from Dart only.
4+
15
## v10.13.0 (2022-03-31)
26

37
* Adds support for uploading debug symbols on Android to be used for crash deobfuscation

README.md

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,26 @@ allprojects {
6262
```
6363

6464

65-
2. Create a new Java class that extends `FlutterApplication` and add it to your `AndroidManifest.xml`.
65+
2. **⚠️ For Instabug versions <= v10.11.0 only.**
66+
Initialize the android SDK:
6667

67-
```xml
68-
<application
69-
android:name=".CustomFlutterApplication"
70-
...
71-
</application>
72-
````
68+
1. Create a new Java class that extends `FlutterApplication` and add it to your `AndroidManifest.xml`.
7369

74-
3. In your newly created `CustomFlutterApplication` class, override `onCreate()` and add the following code.
70+
```xml
71+
<application
72+
android:name=".CustomFlutterApplication"
73+
...
74+
</application>
75+
````
7576

77+
1. In your newly created `CustomFlutterApplication` class, override `onCreate()` and add the following code.
7678

77-
```java
78-
ArrayList<String> invocationEvents = new ArrayList<>();
79-
invocationEvents.add(InstabugFlutterPlugin.INVOCATION_EVENT_SHAKE);
80-
new InstabugFlutterPlugin().start(CustomFlutterApplication.this, "APP_TOKEN", invocationEvents);
81-
```
79+
80+
```java
81+
ArrayList<String> invocationEvents = new ArrayList<>();
82+
invocationEvents.add(InstabugFlutterPlugin.INVOCATION_EVENT_SHAKE);
83+
new InstabugFlutterPlugin().start(CustomFlutterApplication.this, "APP_TOKEN", invocationEvents);
84+
```
8285

8386
## Crash reporting
8487

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.instabug.instabugflutter;
22

33
import android.app.Application;
4+
import android.content.Context;
45
import android.graphics.Bitmap;
56
import android.net.Uri;
67
import android.os.Handler;
@@ -72,26 +73,28 @@ public class InstabugFlutterPlugin implements MethodCallHandler, FlutterPlugin {
7273
private InstabugCustomTextPlaceHolder placeHolder = new InstabugCustomTextPlaceHolder();
7374
HashMap<String, ExecutionTrace> traces = new HashMap<String, ExecutionTrace>();
7475

76+
private static Context context;
7577
static MethodChannel channel;
7678

7779
/**
7880
* Plugin registration.
7981
*/
8082
public static void registerWith(Registrar registrar) {
81-
register(registrar.messenger());
83+
register(registrar.context().getApplicationContext(), registrar.messenger());
8284
}
8385

8486
@Override
8587
public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
86-
register(binding.getBinaryMessenger());
88+
register(binding.getApplicationContext(), binding.getBinaryMessenger());
8789
}
8890

8991
@Override
9092
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
91-
93+
context = null;
9294
}
9395

94-
private static void register(BinaryMessenger messenger){
96+
private static void register(Context applicationContext, BinaryMessenger messenger){
97+
context = applicationContext;
9598
channel = new MethodChannel(messenger, "instabug_flutter");
9699
channel.setMethodCallHandler(new InstabugFlutterPlugin());
97100
}
@@ -144,21 +147,24 @@ private void setCurrentPlatform() {
144147
/**
145148
* starts the SDK
146149
*
147-
* @param application the application Object
148150
* @param token token The token that identifies the app, you can find
149151
* it on your dashboard.
150152
* @param invocationEvents invocationEvents The events that invoke the SDK's UI.
151153
*/
152-
public void start(Application application, String token, ArrayList<String> invocationEvents) {
154+
public void startWithToken(String token, ArrayList<String> invocationEvents) {
153155
setCurrentPlatform();
154156
InstabugInvocationEvent[] invocationEventsArray = new InstabugInvocationEvent[invocationEvents.size()];
155157
for (int i = 0; i < invocationEvents.size(); i++) {
156158
String key = invocationEvents.get(i);
157159
invocationEventsArray[i] = ArgsRegistry.getDeserializedValue(key, InstabugInvocationEvent.class);
158160
}
159-
new Instabug.Builder(application, token).setInvocationEvents(invocationEventsArray).build();
160-
enableScreenShotByMediaProjection();
161161

162+
final Application application = (Application) context;
163+
new Instabug.Builder(application, token)
164+
.setInvocationEvents(invocationEventsArray)
165+
.build();
166+
167+
enableScreenShotByMediaProjection();
162168
}
163169

164170
/**

example/android/app/src/main/AndroidManifest.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
additional functionality it is fine to subclass or reimplement
1414
FlutterApplication and put your custom class here. -->
1515
<application
16-
android:name=".CustomFlutterApplication"
1716
android:label="InstabugSample"
1817
android:icon="@mipmap/ic_launcher">
1918
<activity

example/android/app/src/main/kotlin/com/example/InstabugSample/CustomFlutterApplication.java

Lines changed: 0 additions & 18 deletions
This file was deleted.

lib/Instabug.dart

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,10 @@ class Instabug {
102102
/// the SDK's UI.
103103
static Future<void> start(
104104
String token, List<InvocationEvent> invocationEvents) async {
105-
if (PlatformManager.instance.isIOS()) {
106-
final List<String> invocationEventsStrings =
107-
invocationEvents.map((e) => e.toString()).toList(growable: false);
108-
final List<dynamic> params = <dynamic>[token, invocationEventsStrings];
109-
await _channel.invokeMethod<Object>(
110-
'startWithToken:invocationEvents:', params);
111-
}
105+
final List<String> invocationEventsStrings =
106+
invocationEvents.map((e) => e.toString()).toList(growable: false);
107+
final List<dynamic> params = <dynamic>[token, invocationEventsStrings];
108+
await _channel.invokeMethod<Object>('startWithToken:invocationEvents:', params);
112109
}
113110

114111
/// Shows the welcome message in a specific mode.

test/instabug_flutter_test.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,7 @@ void main() {
102102
log.clear();
103103
});
104104

105-
test('startWithToken:invocationEvents: should be called on iOS', () async {
106-
when(mockPlatform.isIOS()).thenAnswer((_) => true);
107-
105+
test('startWithToken:invocationEvents: should be called', () async {
108106
await Instabug.start(appToken, invocationEvents);
109107
final List<dynamic> args = <dynamic>[
110108
appToken,

0 commit comments

Comments
 (0)