Skip to main content

Add the Embrace Flutter SDK

Add the Embrace SDK to your project

Add the Embrace package to your pubspec.yaml:

flutter pub add embrace

iOS setup

Log in to the Embrace dashboard and create a project. The dashboard contains the app ID and API token that you need for configuring your integration.

Then modify your AppDelegate to initialize Embrace in the init function:

import EmbraceIO
import EmbraceCore
import EmbraceCrash

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override init() {
super.init()
do {
try Embrace
.setup(
options: Embrace.Options(
appId: "", // Your App ID from Embrace Dash
platform: .flutter
)
)
.start()
} catch let e {
print("Error starting Embrace \(e.localizedDescription)")
}
}
}

Upload symbol files

info

Embrace uploads your application's dSYM symbol files using a script bundled with the Embrace iOS SDK. This makes stacktraces from crashes human-readable.

On the Xcode Build Phases 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"

Android setup

In the root-level build.gradle file, add the embrace-swazzler dependency:

  buildscript {
repositories {
mavenCentral()
google()
}
dependencies {
classpath "io.embrace:embrace-swazzler:${findProject(':embrace_android').properties['emb_android_sdk']}"
}
}

In the app/build.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_APP_ID}",
"api_token": "{YOUR_APP_TOKEN}",
"ndk_enabled": true,
"sdk_config": {
"app_framework": "flutter"
}
}

Import Embrace

Import Embrace in the file where your main() function exists:

import 'package:embrace/embrace.dart';

Add the Flutter SDK start call

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

import 'package:embrace/embrace.dart';

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

Add the Android SDK start call

The call to start the Embrace Android SDK should be placed in the onCreate method of an Application subclass:

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

class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
Embrace.getInstance().start(this)
}
}

Build and run the application

Now you're ready to build and run the application. When the app launches, check the system logs and look for Embrace to print its version number:

Embrace Flutter SDK Version: 4.2.0
info

If you encounter any errors, reach out on Slack and we can help.

Trigger a session upload

To trigger a session upload, send the application to the background. The SDK usually has enough time to upload the session, but sometimes the app can't complete the upload in the background. To ensure the session was uploaded, launch the application again and refresh the dashboard in your browser. You should see that you've moved on to the next step.