embrace 0.1.0 copy "embrace: ^0.1.0" to clipboard
embrace: ^0.1.0 copied to clipboard

outdated

Embrace SDK for Flutter

Embrace SDK for Flutter #

This is a development version of the Embrace SDK for Flutter and is not intended for general use.

Integration #

Dart setup #

Add the Embrace package to your pubspec.yaml.

flutter pub add embrace

Wrap the entire contents of your Dart’s main function in Embrace.instance.start(). It is essential to wrap the entire contents of main() if you want Embrace to capture Dart errors.

Future<void> main() async {
  await Embrace.instance.start(() => runApp(const MyApp()));
}

Perform additional setup for Android & iOS as described below.

iOS setup #

Add the following to AppDelegate.m:

#import AppDelegate.h
#import <Embrace/Embrace.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *) application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[Embrace sharedInstance] startWithLaunchOptions:launchOptions framework:EMBAppFrameworkFlutter];
    /*
    Initialize additional crash reporters and
    any other libraries to track *after* Embrace, including
    network libraries, 3rd party SDKs
    */
  return YES;
}
@end
Swift version
import UIKit
import Flutter
import Embrace

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
  _ application: UIApplication,
  didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
  Embrace.sharedInstance().start(launchOptions: launchOptions, framework: EMBAppFramework.flutter)
  /*
      Initialize additional crash reporters and
      any other libraries to track *after* Embrace, including
      network libraries, 3rd party SDKs
  */
  return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}

On the Xcode Build Phase tab, add a new run script. You can find your 5-character app ID and API token in the Embrace dashboard:

EMBRACE_ID=YOUR_APP_ID EMBRACE_TOKEN=YOUR_API_TOKEN "${PODS_ROOT}/EmbraceIO/run.sh"

Create the Embrace-Info.plist configuration file. You can find your 5-character app ID and API token in the Embrace dashboard:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>API_KEY</key>
    <string>{YOUR_APP_ID}</string>
    <key>CRASH_REPORT_ENABLED</key>
    <true/>
</dict>
</plist>

End the startup moment as close to the point that your UI is ready for use by adding the following to AppDelegate.m:

[[Embrace sharedInstance] endAppStartup];

Android setup #

In the root-level build.gradle Gradle file, add:

buildscript {
    repositories {
        mavenCentral()
        google()
    }
    dependencies {
       classpath 'io.embrace:embrace-swazzler:5.7.0'
    }

In the app/build.gradle Gradle file, add:

apply plugin 'com.android.application'
apply plugin 'embrace-swazzler'

In app/src/main, add a config file named embrace-config.json. You can find your 5-character app ID and API token in the Embrace dashboard:

{
    "app_id": "<your Embrace app ID>",
    "api_token": "<your Embrace API token>",
    "ndk_enabled": true
}

In your custom Activity class like in MyApplication.java, add:

import io.embrace.android.embracesdk.Embrace;
import android.app.Application;

public final class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        Embrace.getInstance().start(this, false, Embrace.AppFramework.FLUTTER);
    }
}
Kotlin version
import android.os.Bundle
import io.embrace.android.embracesdk.Embrace
import io.flutter.embedding.android.FlutterActivity

class MainActivity: FlutterActivity() {

  override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      Embrace.getInstance().start(this, false, Embrace.AppFramework.FLUTTER)
  }
}

If you do not already have a custom Application class, create a new source file matching the previous step then edit your AndroidManifest.xml to use your new custom Application class. Make sure you edit AndroidManifest.xml under the main sourceSet as well as any under debug/other sourceSets:

<application android:name=".MyApplication">

Verify Your Integration #

Build and run your app. The Embrace Dashboard will display the following session data:

  • Views and taps
  • First-party and third-party network calls (200s, 4xx, 5xx, and connection errors) with timing and call sizes
  • Low memory and out-of-memory
  • CPU pegging
  • Low power mode
  • Connectivity (Wifi, cellular, and switches between them)
  • Device information (OS version, device, disk usage)
  • Crashes
  • User terminations