Adding the Embrace SDK

Adding the React Native Embrace SDK #

Add the JavaScript library #

Use Yarn or NPM to install the NPM module.

yarn add react-native-embrace
npm install react-native-embrace --save

Use Autolinking #

If you’re on React Native version 0.60 and above, you can use Autolinking to setup the native modules.

Add the EmbraceIO Pod.

cd ios && pod install
Follow the steps in the Setup Script section or the Manual section to add the Android native dependencies.

Using the Setup Script #

The JavaScript Embrace SDK ships with a setup script to modify the files in your project to add the native dependencies. The setup script can be found in your node_modules folder at node_modules/react-native-embrace/dist/scripts/setup/setup.js

node node_modules/react-native-embrace/dist/scripts/setup/setup.js

You can use git to see the changes that the script made.

git diff

Compare the changes to the Manual Setup step to verify the changes were made correctly.

Adding the SDK Manually #

Configure your PodFile to add Embrace.

target 'MyApp' do
  # ...

  pod 'EmbraceIO'
  pod 'RNEmbrace', :path => '../node_modules/react-native-embrace'
end

Then, install the pod.

pod install

Finally, you’ll need to add an Embrace-Info.plist file at the root of the iOS project. Please see the Session Reporting page from the iOS integration guide page on how to add this file in Xcode.

Update the build.gradle file (usually located at <root>/android/build.gradle) to include the Embrace Swazzler.

buildscript {
  repositories {
    jcenter()
    google()
  }
  dependencies {
    classpath('embrace-io:embrace-swazzler:4.5.1')
  }
}

Then, update the app build.gradle file (usually located at <root>/android/app/build.gradle).

apply plugin: 'com.android.application'
apply plugin: 'embrace-swazzler'
repositories {
  jcenter()
  google()
}

React Native 0.59.0 and later automatically adds the required compileOptions directive to the android/app/build.gradle file. If you are using a version of React Native older than 0.59.0, or your project was created with a version older than 0.59.0, add the following to your android/app/build.gradle file:

android {
    // ...

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    // ...
}

Now, add the Embrace config file at android/app/src/main/embrace-config.json, and add your API key and token.

{
  "app_id": "xxxxx",
  "api_token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
Your API ID and token are available on the Embrace dashboard.

You’ll need to set the following permissions so the Embrace SDK can send events and monitor connectivity.

  • android.permission.INTERNET
  • android.permission.ACCESS_NETWORK_STATE

There’s a little more configuration we have to do to setup the uploading of symbol files. You’ll be learning about that next.

On to Uploading Symbol Files