Skip to content

Commit

Permalink
🎉 Unifying native SDKs initialization (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
alyezz authored Sep 5, 2019
1 parent 608061f commit 2340999
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 63 deletions.
12 changes: 6 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ jobs:
- run:
name: Install emulator dependencies
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
- run:
name: download flutter SDK
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
- run:
name: unzip flutter SDK
command: unzip flutter_sdk.zip
- run:
name: chmod permissions
command: chmod +x ./gradlew
Expand All @@ -44,6 +38,12 @@ jobs:
name: Run emulator in background
command: /usr/local/share/android-sdk/tools/emulator @Pixel_2_API_26 -noaudio -no-boot-anim -no-window
background: true
- run:
name: download flutter SDK
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
- run:
name: unzip flutter SDK
command: unzip flutter_sdk.zip
- run:
name: Flutter build
command: cd ..; flutter build aot
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Master

* You can now initialize Instabug on Android by calling `Instabug.start` from Javascript, instead of calling the builder method from the application class.
* Updates native SDK dependencies to 8.6.2

## Version 8.6.1 (2019-08-26)

* Bumps version to 8.6 to be in sync with other platforms.
Expand Down
19 changes: 2 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ flutter packages get
import 'package:instabug_flutter/Instabug.dart';
```

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.
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.

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

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

Expand All @@ -62,24 +63,8 @@ allprojects {
}
```

Make sure to replace `app_token` with your application token.

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

```xml
<application
android:name=".CustomFlutterApplication"
...
</application>
````

5. In your newly created `CustomFlutterApplication` class, override `onCreate()` and add the following code.

```java
ArrayList<String> invocationEvents = new ArrayList<>();
invocationEvents.add(InstabugFlutterPlugin.INVOCATION_EVENT_SHAKE);
new InstabugFlutterPlugin().start(CustomFlutterApplication.this, "APP_TOKEN", invocationEvents);
```

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

Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ android {
}

dependencies {
implementation 'com.instabug.library:instabug:8.6.1.0'
implementation 'com.instabug.library:instabug:8.6.3.0'
testImplementation 'junit:junit:4.12'
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,15 @@
*/
public class InstabugFlutterPlugin implements MethodCallHandler {

final public static String INVOCATION_EVENT_NONE = "InvocationEvent.none";
final public static String INVOCATION_EVENT_SCREENSHOT = "InvocationEvent.screenshot";
final public static String INVOCATION_EVENT_TWO_FINGER_SWIPE_LEFT = "InvocationEvent.twoFingersSwipeLeft";
final public static String INVOCATION_EVENT_FLOATING_BUTTON = "InvocationEvent.floatingButton";
final public static String INVOCATION_EVENT_SHAKE = "InvocationEvent.shake";

private InstabugCustomTextPlaceHolder placeHolder = new InstabugCustomTextPlaceHolder();

static MethodChannel channel;
static Registrar myRegistrar;
/**
* Plugin registration.
*/
public static void registerWith(Registrar registrar) {
myRegistrar = registrar;
channel = new MethodChannel(registrar.messenger(), "instabug_flutter");
channel.setMethodCallHandler(new InstabugFlutterPlugin());
}
Expand Down Expand Up @@ -102,19 +98,18 @@ public void onMethodCall(MethodCall call, Result result) {
/**
* starts the SDK
*
* @param application the application Object
* @param token token The token that identifies the app, you can find
* it on your dashboard.
* @param invocationEvents invocationEvents The events that invoke
* the SDK's UI.
*/
public void start(Application application, String token, ArrayList<String> invocationEvents) {
public void startWithToken( String token, ArrayList<String> invocationEvents) {
InstabugInvocationEvent[] invocationEventsArray = new InstabugInvocationEvent[invocationEvents.size()];
for (int i = 0; i < invocationEvents.size(); i++) {
String key = invocationEvents.get(i);
invocationEventsArray[i] = ArgsRegistry.getDeserializedValue(key, InstabugInvocationEvent.class);
}
new Instabug.Builder(application, token).setInvocationEvents(invocationEventsArray).build();
new Instabug.Builder(myRegistrar.activity().getApplication(), token).setInvocationEvents(invocationEventsArray).build();
enableScreenShotByMediaProjection();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ public class InvokeInstabugUITest {
@Test
public void ensureInstabugInvocati1on() throws InterruptedException {
disableScreenShotByMediaProjection();
Thread.sleep(1000);
onView(withResourceName("instabug_floating_button")).perform(click());
Thread.sleep(5000);
Thread.sleep(1000);
onView(withText("Report a bug")).perform(click());
Thread.sleep(5000);
Thread.sleep(1000);
onView(withResourceName("instabug_edit_text_email")).perform(replaceText("[email protected]"));
onView(withResourceName("instabug_bugreporting_send")).perform(click());
onView(withResourceName("instabug_success_dialog_container")).perform(click());
Expand Down
2 changes: 1 addition & 1 deletion example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name=".CustomFlutterApplication"
android:name="io.flutter.app.FlutterApplication"
android:label="instabug_flutter_example"
android:icon="@mipmap/ic_launcher">
<activity
Expand Down

This file was deleted.

Empty file modified example/android/gradlew
100644 → 100755
Empty file.
9 changes: 1 addition & 8 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,14 @@ class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
Instabug.start('efa41f402620b5654f2af2b86e387029', <InvocationEvent>[InvocationEvent.floatingButton]);
initPlatformState();
}

// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
if (Platform.isIOS) {
Instabug.start('efa41f402620b5654f2af2b86e387029', <InvocationEvent>[InvocationEvent.floatingButton]);
BugReporting.setReportTypes([ReportType.bug, ReportType.feedback]);
}
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
Expand Down
2 changes: 1 addition & 1 deletion ios/instabug_flutter.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ A new flutter plugin project.
s.source_files = 'Classes/**/*'
s.public_header_files = 'Classes/**/*.h'
s.dependency 'Flutter'
s.dependency 'Instabug', '8.6.1'
s.dependency 'Instabug', '8.6.2'

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

0 comments on commit 2340999

Please sign in to comment.