Skip to main content
Version: 3.7.0

SDK Integration Guide

SDK Integration

Local

1. Prepare Bonree SDK Environment

Unzip BonreeSDK_TDEM_Android.v${VERSION_NAME}.zip and store it locally (e.g., E:);

Copy the contents of the jniLibs directory to overwrite the jniLibs directory in your packaging module level that stores so dynamic libraries (if there is no jniLibs directory in your project, please create one);

Copy the repo folder to the root directory of all Projects, at the same level as the module directory;

Copy com.bonree.sdk.jar to the libs directory at the module level;

Note: On Mac, it is best to place the unzipped folder path under /Users/xxxx/. Placing it in a system directory may cause unexpected issues due to permissions.

2. Configure Gradle

2.1 For Gradle Versions Below 7.0

Open the build.gradle file in the root directory of all Project levels.

image-20200827155642973

Add the following three configuration scripts (highlighted in red boxes) to the build.gradle file, and click the Sync Now button.

image-20200827155642973

ext.brsdk_version = '8.0.0' // The value of ext.brsdk_version is the SDK version number, usually found at the end of the downloaded zip file name or in the Download Center.
maven { url uri('./repo') }
classpath "com.bonree.agent.android:bonree:$brsdk_version"

Open the build.gradle file in all module-level directories.

image-20200827155642973

Add the following code in the dependencies block:

implementation files('libs/com.bonree.sdk.jar')

image-20200827155642973

Apply the Bonree plugin at the top of the file:

apply plugin: 'bonree'

image-20200827155642973

2.2 For Gradle Version 7.0 and Above

Open the settings.gradle file in the Project root directory.

image-20200827155642973

Add the following configuration content (highlighted in the red box) to the settings.gradle file, and click the Sync Now button.

image-20200827155642973

maven { url uri('./repo') }

Open the build.gradle file in the Project root directory.

image-20200827155642973

Add the content highlighted in the red box and click the Sync Now button.

image-20200827155642973

  buildscript {
ext.brsdk_version = '8.0.0'
dependencies {
classpath "com.bonree.agent.android:bonree:$brsdk_version"
}
}

Open the build.gradle file in the main Module directory, add the following configuration in the dependencies block, and click the Sync Now button.

image-20200827155642973

implementation files('libs/com.bonree.sdk.jar')

Also, apply the Bonree plugin at the top of this file and click the Sync Now button.

image-20200827155642973

3. Rebuild & Clean the Project

Rebuild & Clean the project to ensure the Bonree configuration takes effect.

image-20200827155642973

Remote

1. Configure Gradle

1.1 For Gradle Versions Below 7.0

Open the build.gradle file in the root directory of all Project levels.

image-20200827155642973

Add the following three configuration scripts (highlighted in red boxes) to the build.gradle file, and click the Sync Now button.

image-20200827155642973

ext.brsdk_version = '8.0.0'
// The value of ext.brsdk_version is the SDK version number. Specific version numbers can be found in the Download Center.
maven {
url 'https://gitlab.bonree.com/BonreeSDK_TAPM/Android/raw/master'
}
classpath "com.bonree.agent.android:bonree:$brsdk_version"

Open the build.gradle file in all module-level directories.

image-20200827155642973

Add the following code in the dependencies block:

implementation "com.bonree.agent.android:agent-lib:$brsdk_version"

image-20200827155642973

Apply the Bonree plugin at the top of the file:

apply plugin: 'bonree'

image-20200827155642973

1.2 For Gradle Version 7.0 and Above

Open the settings.gradle file in the Project root directory.

image-20200827155642973

Add the following configuration content (highlighted in the red box) to the settings.gradle file, and click the Sync Now button.

image-20200827155642973

maven {
url 'https://gitlab.bonree.com/BonreeSDK_TAPM/Android/raw/master'
}

Open the build.gradle file in the Project root directory.

image-20200827155642973

Add the content highlighted in the red box and click the Sync Now button.

image-20200827155642973

buildscript {
ext.brsdk_version = '8.0.0'
dependencies {
classpath "com.bonree.agent.android:bonree:$brsdk_version"
}
}

Open the build.gradle file in the main Module directory, add the following configuration in the dependencies block, and click the Sync Now button.

image-20200827155642973

implementation "com.bonree.agent.android:agent-lib:$brsdk_version"

Also, apply the Bonree plugin at the top of this file and click the Sync Now button.

image-20200827155642973

2. Rebuild & Clean the Project

Rebuild & Clean the project to ensure the Bonree configuration takes effect.

image-20200827155642973

SDK Setup

1. Configure Permission Information

Check the application's AndroidManifest.xml configuration file to ensure the following permissions are included:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

2. Configure Obfuscation Settings

If your application uses ProGuard obfuscation, add the following configuration:

#ProGuard configurations for Bonree-Agent 
-keep class com.bonree.**{*;}
-keep class bonree.**{*;}
-dontwarn com.bonree.**
-dontwarn bonree.**
#End Bonree-Agent

If your ProGuard configuration file does not include the -dontoptimize configuration, be sure to add the following:

-optimizations !code/simplification/*,!field/*,!class/merging/*,!method/propagation/*,!class/unboxing/enum,!code/allocation/variable

3. Initialize SDK

<#Config Address#> and <#AppID#> can be obtained from the platform. For the method to obtain them, please refer to How to Query AppID and Config Address?. If you have any questions, please contact technical support.

Add the following code in the onCreate function of your custom Application:

Java:

Bonree.withAppID("<#AppID#>")
.withConfigAddress("<#Config Address#>")
.start(getApplicationContext());

Kotlin:

Bonree.withAppID("<#AppID#>")
.withConfigAddress("<#Config Address#>")
.start(getApplicationContext());

Example usage:

public class App extends Application {

@Override
public void onCreate() {
super.onCreate();
Bonree.withAppID("<#AppID#>")
.withConfigAddress("<#Config Address#>")
.start(getApplicationContext());
}
}

4. WebView Data Collection

Collecting WebView data requires support from WebViewClient and WebChromeClient components.

Scenario 1: If your business code doesn't require custom clients, no additional calls to setWebViewClient or setWebChromeClient are needed.

Scenario 2: If your business requires setting clients, please avoid using the following code patterns:

Java:

Incorrect structure override that affects normal WebView data collection!
Incorrect examples:
webview.setWebViewClient(new WebViewClient());
or
webview.setWebChromeClient(new WebChromeClient());

Correct structure overrides that won't affect WebView data collection:
Correct examples:
webView.setWebChromeClient(new WebChromeClient(){});
webView.setWebViewClient(new WebViewClient(){});
or
CustomWebClient customWebClient = new CustomWebClient();
// CustomWebClient extends WebViewClient
webView.setWebViewClient(customWebClient);
or
webView.setWebViewClient(new WebViewClient(){
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
//do something...
}
});

Kotlin:

Incorrect structure override that affects normal WebView data collection!
Incorrect examples:
webView!!.webViewClient = WebViewClient()
or
webView!!.webChromeClient = WebChromeClient()

Correct structure overrides that won't affect WebView data collection:
Correct examples:
webView!!.webChromeClient = object : WebChromeClient() {}
webView!!.webViewClient = object : WebViewClient() {}
or
// CustomWebClient extends WebViewClient
val customWebClient = CustomWebClient()
webView!!.webViewClient = customWebClient
or
webView!!.webViewClient = object : WebViewClient() {
override fun onPageStarted(view: WebView, url: String, favicon: Bitmap) {
super.onPageStarted(view, url, favicon)
//do something...
}
}

5. Integration Verification

Start the integrated APK and check the logcat logs. Search for the keyword "brsdk" (or filter by the BRSDK-Agent tag). The following logs indicate successful integration and data collection has started:

Brsdk is starting (Note: BRAgent integration successful)
BRAgent enable (Note: BRAgent startup successful)
BRAgent connect server success (Note: BRAgent data configuration successful)
BRAgent v*** (Note: *** represents the BRAgent version corresponding to the current zip file name)

image-20200827155642973

Log Agent Integration

Local Integration

1. Prepare Bonree SDK Environment

Copy the downloaded log SDK file com.bonree.log.jar to the libs directory at the module level of your project (the screenshot example uses a Demo project as an example). As shown in the figure:

dir

2. Sync Gradle

Open the build.gradle file in the module-level directory, add the following code in the dependencies block, and click the Sync Now button.

implementation files('libs/com.bonree.log.jar')

dependency

3. Rebuild & Clean the Project

Rebuild & Clean the project to ensure the Bonree configuration takes effect.

clean

4. Configure Permission Information

Check the application's AndroidManifest.xml configuration file to ensure the following permissions are included:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

5. Configure Obfuscation Settings

# ProGuard configurations for Bonree-Log
-keep class com.bonree.** { *; }
-keep class bonree.** { *; }
-dontwarn com.bonree.**
-dontwarn bonree.**
# End Bonree-Log

Remote Dependency

1. Integration Version

Check the Download Center for the latest version number of Bonree Log SDK to determine the version you want to integrate.

2. Sync Gradle

Open the build.gradle file in the module-level directory, add the following code in the dependencies block, and click the Sync Now button.

implementation 'com.bonree.log:log:1.0.0'

3. Rebuild & Clean Project

Rebuild & Clean the project to ensure the Bonree configuration takes effect.

clean