Bugly Android SDK User Guide

Preparation before access

Please read carefully before accessing the sdk《 Developer Compliance Guide 》And《 Bugly SDK Personal Information Protection Rules

Library file import

Bugly supports automatic integration and manual integration. If you use Gradle to compile Apk, we strongly recommend that you use automatic access to configure the library file.

Automatic integration (recommended)

Bugly Support Maven Central warehouse In order to facilitate version management, jar and so have been merged and released in versions above 4.0.0.

Integration SDK

Add dependency and attribute configurations in the build.gradle file of the Module:

 android { defaultConfig { ndk { //Set the supported SO library architecture abiFilters 'armeabi' //, 'x86', 'armeabi-v7a', 'x86_64', 'arm64-v8a' } } } dependencies { Implementation 'com. test. bug: crash report: latest. release'//where latest. release refers to the latest bug SDK version number, or you can specify a specific version number, such as 4.0.3 }

Note: Before 4.0.0, you need to add native crash report dependencies:

 Implementation 'com. tencent. rqd: nativecrashreport: latest. release'//where latest. release refers to the latest Bugly NDK version number, or you can specify a specific version number, such as 3.9.2

Note: Bugly SO library will be automatically included during automatic integration. It is recommended to use the "abiFilter" configuration of NDK in the build.gradle file of the module to set the supported SO library architecture.

If adding “abiFilter” Then the following prompt appears in Android Studio:

NDK integration is deprecated in the current plugin. Consider trying the new experimental plugin.

In the project root directory gradle.properties Add:

android.useDeprecatedNdk=true

Manual integration (not recommended)

If you do not use the above automatic import method, you can also manually integrate the Bugly SDK.

Download the Bugly aar file

Android Studio project

  • Copy the aar file to the libs directory of the module, and add dependencies in the gradle file of the module:
 dependencies { implementation files('libs/Bugly_sdk.aar') }

To make the APP Crash stack more readable, it is recommended that you configure symbol table files to locate problems more accurately:

  • Pure Java code project: just configure the Mapping file generated after confusion;
  • Projects containing native code: It is recommended to configure symbol table files extracted from Debug SO by symbol table tools.

Please refer to:《 Bugly Android symbol table configuration

Parameter configuration

  • Add permissions in AndroidManifest.xml:
 <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
  • To avoid confusing Bugly, add the following configurations to the Proguard confusion file:
 -dontwarn com.tencent.bugly.** -keep public class com.tencent.bugly.**{*;}

The simplest initialization

Please make sure that you have upgraded the Bugly SDK to the latest version that meets the new regulatory regulations
Please be sure to initialize the Bugly SDK after the user authorizes the Privacy Policy

Get the APP ID and call the initialization method. Bugly will automatically detect the environment and complete the configuration:

 CrashReport. initCrashReport (getApplicationContext(), "APPID applied during registration", false);
  • To ensure the accuracy of operation data, it is recommended not to initialize Bugly in asynchronous threads.

The third parameter is the SDK debug mode switch. The behavior characteristics of the debug mode are as follows:

  • Output detailed Bugly SDK logs;
  • Every crash will be reported immediately;
  • Custom logs will be output in Logcat.

It is recommended to set it to true during testing and false during publishing.

 Alt text

In addition, Bugly2.0 and above also support the configuration of APP information through "AndroidManifest. xml". If APP information is configured in the code at the same time, the information configured in the code shall prevail.

Add "meta data" configuration item in "Application" of "AndroidManifest.xml":

 <application <!--  Configure APP ID --> <meta-data android:name="BUGLY_APPID" android:value="<APP_ID>" /> <!--  Configure the APP version number --> <meta-data android:name="BUGLY_APP_VERSION" android:value="<APP_Version>" /> <!--  Configure APP channel number --> <meta-data android:name="BUGLY_APP_CHANNEL" android:value="<APP_Channel>" /> <!--  Configure the Bugly debug mode (true or false) --> <meta-data android:name="BUGLY_ENABLE_DEBUG" android:value="<isDebug>" /> </application>

Unlike "android: versionName", "BUGLY_APP_VERSION" configures the APP version number of the Bugly platform.

The initialization method after configuration through "AndroidManifest. xml" is as follows:

 CrashReport.initCrashReport(getApplicationContext());

Bugly reads "VersionName" from the "AndroidManifest. xml" file as the version number by default

Bugly provides more customized function settings, please refer to“ Advanced Features ”。

Compliance problem handling

  • The latest version of SDK will not obtain the unique ID of the device In order to make the crash rate statistics more accurate, it is recommended that the business set its own unique ID to the SDK, as shown in Advanced Features -Set device id
  • The latest SDK will not get the phone model by default If necessary, please set the phone model to the SDK after obtaining the phone model in compliance, see Advanced Features -Set device model

MultiDex Considerations

If MultiDex is used, it is recommended to use Gradle's“ multiDexKeepFile ”Configure the Bugly class to the main Dex Application Class“ attachBaseContext "Active loading of non primary dex in the method:

 public class MyApplication extends SomeOtherApplication { @Override protected void attachBaseContext(Context base) { super.attachBaseContext(context); Multidex.install(this); } }

Test and Demo

Now you can create a crash (it is recommended to trigger it by pressing a key) to experience Bugly's ability. After initializing Bugly, call Bugly to test the Java Crash interface.

 CrashReport.testJavaCrash();

When this code is executed, a crash will occur. The output in Logcat's TAG=CrashReportInfo is:

 Alt text

Now you can Crash The page sees the crash issue triggered just now (the delay is generally within 10s).

Reference demo https://github.com/BuglyDevTeam/Bugly-Android-Demo

If the project contains Native projects or uses code obfuscation, it is recommended to configure symbol table files. For details, refer to“ Symbol Table Configuration