Skip to content

Commit 2340999

Browse files
authored
🎉 Unifying native SDKs initialization (#87)
1 parent 608061f commit 2340999

File tree

11 files changed

+24
-63
lines changed

11 files changed

+24
-63
lines changed

.circleci/config.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ jobs:
3030
- run:
3131
name: Install emulator dependencies
3232
command: (yes | sdkmanager "platform-tools" "platforms;android-26" "extras;intel;Hardware_Accelerated_Execution_Manager" "build-tools;26.0.0" "system-images;android-26;google_apis;x86" "emulator" --verbose) || true
33-
- run:
34-
name: download flutter SDK
35-
command: if ! test -f "flutter_sdk.zip"; then curl -o flutter_sdk.zip https://storage.googleapis.com/flutter_infra/releases/stable/macos/flutter_macos_v1.5.4-hotfix.2-stable.zip; fi
36-
- run:
37-
name: unzip flutter SDK
38-
command: unzip flutter_sdk.zip
3933
- run:
4034
name: chmod permissions
4135
command: chmod +x ./gradlew
@@ -44,6 +38,12 @@ jobs:
4438
name: Run emulator in background
4539
command: /usr/local/share/android-sdk/tools/emulator @Pixel_2_API_26 -noaudio -no-boot-anim -no-window
4640
background: true
41+
- run:
42+
name: download flutter SDK
43+
command: if ! test -f "flutter_sdk.zip"; then curl -o flutter_sdk.zip https://storage.googleapis.com/flutter_infra/releases/stable/macos/flutter_macos_v1.5.4-hotfix.2-stable.zip; fi
44+
- run:
45+
name: unzip flutter SDK
46+
command: unzip flutter_sdk.zip
4747
- run:
4848
name: Flutter build
4949
command: cd ..; flutter build aot

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## Master
2+
3+
* You can now initialize Instabug on Android by calling `Instabug.start` from Javascript, instead of calling the builder method from the application class.
4+
* Updates native SDK dependencies to 8.6.2
5+
16
## Version 8.6.1 (2019-08-26)
27

38
* Bumps version to 8.6 to be in sync with other platforms.

README.md

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ flutter packages get
4444
import 'package:instabug_flutter/Instabug.dart';
4545
```
4646

47-
2. Initialize the SDK in `initState()`. This line enables the SDK with the default behavior and sets it to be shown when the device is shaken. Ignore this if you're building for Android only.
47+
2. Initialize the SDK in `initState()`. This line enables the SDK with the default behavior and sets it to be shown when the device is shaken.
4848

4949
```dart
5050
Instabug.start('APP_TOKEN', [InvocationEvent.shake]);
5151
```
52+
Make sure to replace `app_APP_TOKEN` with your application token.
5253

5354
3. Add the following Maven repository to your project level `build.gradle`
5455

@@ -62,24 +63,8 @@ allprojects {
6263
}
6364
```
6465

65-
Make sure to replace `app_token` with your application token.
6666

67-
4. If your app supports Android, create a new Java class that extends `FlutterApplication` and add it to your `AndroidManifest.xml`.
6867

69-
```xml
70-
<application
71-
android:name=".CustomFlutterApplication"
72-
...
73-
</application>
74-
````
75-
76-
5. In your newly created `CustomFlutterApplication` class, override `onCreate()` and add the following code.
77-
78-
```java
79-
ArrayList<String> invocationEvents = new ArrayList<>();
80-
invocationEvents.add(InstabugFlutterPlugin.INVOCATION_EVENT_SHAKE);
81-
new InstabugFlutterPlugin().start(CustomFlutterApplication.this, "APP_TOKEN", invocationEvents);
82-
```
8368

8469
## Microphone and Photo Library Usage Description (iOS Only)
8570

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ android {
3434
}
3535

3636
dependencies {
37-
implementation 'com.instabug.library:instabug:8.6.1.0'
37+
implementation 'com.instabug.library:instabug:8.6.3.0'
3838
testImplementation 'junit:junit:4.12'
3939
}

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,15 @@
5151
*/
5252
public class InstabugFlutterPlugin implements MethodCallHandler {
5353

54-
final public static String INVOCATION_EVENT_NONE = "InvocationEvent.none";
55-
final public static String INVOCATION_EVENT_SCREENSHOT = "InvocationEvent.screenshot";
56-
final public static String INVOCATION_EVENT_TWO_FINGER_SWIPE_LEFT = "InvocationEvent.twoFingersSwipeLeft";
57-
final public static String INVOCATION_EVENT_FLOATING_BUTTON = "InvocationEvent.floatingButton";
58-
final public static String INVOCATION_EVENT_SHAKE = "InvocationEvent.shake";
59-
6054
private InstabugCustomTextPlaceHolder placeHolder = new InstabugCustomTextPlaceHolder();
6155

6256
static MethodChannel channel;
57+
static Registrar myRegistrar;
6358
/**
6459
* Plugin registration.
6560
*/
6661
public static void registerWith(Registrar registrar) {
62+
myRegistrar = registrar;
6763
channel = new MethodChannel(registrar.messenger(), "instabug_flutter");
6864
channel.setMethodCallHandler(new InstabugFlutterPlugin());
6965
}
@@ -102,19 +98,18 @@ public void onMethodCall(MethodCall call, Result result) {
10298
/**
10399
* starts the SDK
104100
*
105-
* @param application the application Object
106101
* @param token token The token that identifies the app, you can find
107102
* it on your dashboard.
108103
* @param invocationEvents invocationEvents The events that invoke
109104
* the SDK's UI.
110105
*/
111-
public void start(Application application, String token, ArrayList<String> invocationEvents) {
106+
public void startWithToken( String token, ArrayList<String> invocationEvents) {
112107
InstabugInvocationEvent[] invocationEventsArray = new InstabugInvocationEvent[invocationEvents.size()];
113108
for (int i = 0; i < invocationEvents.size(); i++) {
114109
String key = invocationEvents.get(i);
115110
invocationEventsArray[i] = ArgsRegistry.getDeserializedValue(key, InstabugInvocationEvent.class);
116111
}
117-
new Instabug.Builder(application, token).setInvocationEvents(invocationEventsArray).build();
112+
new Instabug.Builder(myRegistrar.activity().getApplication(), token).setInvocationEvents(invocationEventsArray).build();
118113
enableScreenShotByMediaProjection();
119114
}
120115

example/android/app/src/androidTest/java/com/instabug/instabugflutterexample/InvokeInstabugUITest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ public class InvokeInstabugUITest {
2626
@Test
2727
public void ensureInstabugInvocati1on() throws InterruptedException {
2828
disableScreenShotByMediaProjection();
29+
Thread.sleep(1000);
2930
onView(withResourceName("instabug_floating_button")).perform(click());
30-
Thread.sleep(5000);
31+
Thread.sleep(1000);
3132
onView(withText("Report a bug")).perform(click());
32-
Thread.sleep(5000);
33+
Thread.sleep(1000);
3334
onView(withResourceName("instabug_edit_text_email")).perform(replaceText("[email protected]"));
3435
onView(withResourceName("instabug_bugreporting_send")).perform(click());
3536
onView(withResourceName("instabug_success_dialog_container")).perform(click());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
additional functionality it is fine to subclass or reimplement
1414
FlutterApplication and put your custom class here. -->
1515
<application
16-
android:name=".CustomFlutterApplication"
16+
android:name="io.flutter.app.FlutterApplication"
1717
android:label="instabug_flutter_example"
1818
android:icon="@mipmap/ic_launcher">
1919
<activity

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

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

example/android/gradlew

100644100755
File mode changed.

example/lib/main.dart

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,14 @@ class _MyAppState extends State<MyApp> {
2121
@override
2222
void initState() {
2323
super.initState();
24+
Instabug.start('efa41f402620b5654f2af2b86e387029', <InvocationEvent>[InvocationEvent.floatingButton]);
2425
initPlatformState();
2526
}
2627

2728
// Platform messages are asynchronous, so we initialize in an async method.
2829
Future<void> initPlatformState() async {
2930
String platformVersion;
3031
// Platform messages may fail, so we use a try/catch PlatformException.
31-
try {
32-
if (Platform.isIOS) {
33-
Instabug.start('efa41f402620b5654f2af2b86e387029', <InvocationEvent>[InvocationEvent.floatingButton]);
34-
BugReporting.setReportTypes([ReportType.bug, ReportType.feedback]);
35-
}
36-
} on PlatformException {
37-
platformVersion = 'Failed to get platform version.';
38-
}
3932
// If the widget was removed from the tree while the asynchronous platform
4033
// message was in flight, we want to discard the reply rather than calling
4134
// setState to update our non-existent appearance.

ios/instabug_flutter.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ A new flutter plugin project.
1515
s.source_files = 'Classes/**/*'
1616
s.public_header_files = 'Classes/**/*.h'
1717
s.dependency 'Flutter'
18-
s.dependency 'Instabug', '8.6.1'
18+
s.dependency 'Instabug', '8.6.2'
1919

2020
s.ios.deployment_target = '10.0'
2121
s.pod_target_xcconfig = { 'OTHER_LDFLAGS' => '-framework "Flutter" -framework "Instabug"'}

0 commit comments

Comments
 (0)