Bugly connects to implement online exception reporting and sends exception information to developers in real time via WeChat

One of the requirements of recent projects is to count the abnormal information of the App, and the abnormal information must be notified to developers in real time, so that developers can grasp online exceptions at the first time, and find the problem in a timely manner based on exceptions reported by customers. Subsequently, through Alibaba Cloud's HotFix performs online timely repairs. Currently, the most commonly used third-party mobile platforms for quality tracking on the market include Umeng, Bugly, NetEase Cloud Capture and crashlytics. Among them, the first three are third parties for domestic anomaly statistics. Domestic developers use the first three more. Currently, I have personally used Umeng and Bugly. Both of them are very easy to access and provide abnormal statistics in the background. It's all very clear.

First, let’s take a look at Bugly’s access:

Register product

  • Log in

Use QQ to log in to Bugly official website

Alt text

  • Improve developer information

Complete the developer information before creating the product: Fill in the email, WeChat ID and mobile phone number as required so that you can receive product updates in time, and it also makes it easier for us to keep in touch with the developers at any time.

Alt text

  • Create app

Add the application name, select the application platform, product type, product icon and description information as required.

Alt text

After saving, it will be created successfully.

Alt text

Introduction to platform functions

After the application integrates the SDK, you can view the crash data and networking data reported by the application on the website.

Abnormal reporting

  • 异常概览View today’s real-time statistics, crash trends, crash rankings, and TOP20 crash issues and other information

Alt text

Alt text

  • 崩溃分析/卡顿分析/错误分析View a list of reported issues

Alt text

  • 问题详情View details of reported issues

Alt text

Alt text

  • 高级搜索Quickly find anomalies that need to be located and analyzed through various conditions

Alt text

Library file import

Bugly supports automatic integration and manual integration. If you use Gradle to compile the Apk, it is strongly recommended that you use the automatic access method to configure the library file.

 

Integrate SDK and NDK simultaneously

Add dependencies and property configurations in the Module's build.gradle file:

android {
    defaultConfig {
        ndk {
            // 设置支持的SO库架构
            abiFilters 'armeabi' //, 'x86', 'armeabi-v7a', 'x86_64', 'arm64-v8a'
        }
    }
}

dependencies {
    compile 'com.tencent.bugly:crashreport:latest.release' //其中latest.release指代最新Bugly SDK版本号,也可以指定明确的版本号,例如2.1.9
    compile 'com.tencent.bugly:nativecrashreport:latest.release' //其中latest.release指代最新Bugly NDK版本号,也可以指定明确的版本号,例如3.0
}

The configuration of integrating Bugly SDK and NDK at the same time is shown in the figure below. When updating Bugly SDK and NDK later, you only need to change the version number in the configuration script.

Alt text

注意:自动集成时会自动包含Bugly SO库,建议在Module的build.gradle文件中使用NDK的“abiFilter”配置,设置支持的SO库架构。

If Android Studio displays the following prompt after adding "abiFilter" :

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

Then add: in the gradle.properties file in the project root directory :

android.useDeprecatedNdk=true

Parameter configuration

  • Add permissions in AndroidManifest.xml:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<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" />
<uses-permission android:name="android.permission.READ_LOGS" />

Note: If your app needs to be uploaded to google play store, you need to READ_PHONE_STATEblock or remove permissions, otherwise it may be removed.

  • Please avoid confusing Bugly by adding the following configuration to the Proguard obfuscation file:
-dontwarn com.tencent.bugly.**
-keep public class com.tencent.bugly.**{*;}

The simplest initialization

Get the APP ID and copy the following code to the project Application class onCreate(). Bugly will automatically detect the environment and complete the configuration:

CrashReport.initCrashReport(getApplicationContext(), "注册时申请的APPID", false); 

为了保证运营数据的准确性,建议不要在异步线程初始化Bugly。

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

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

It is recommended to set it to true during the testing phase and to false during release .

Alt text

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

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

<application
    <!-- 配置APP ID -->
    <meta-data
            android:name="BUGLY_APPID"
            android:value="<APP_ID>" />
    <!-- 配置APP版本号 -->
    <meta-data
            android:name="BUGLY_APP_VERSION"
            android:value="<APP_Version>" />
    <!-- 配置APP渠道号 -->
    <meta-data
            android:name="BUGLY_APP_CHANNEL"
            android:value="<APP_Channel>" />
    <!-- 配置Bugly调试模式(true或者false)-->
    <meta-data
            android:name="BUGLY_ENABLE_DEBUG"
            android:value="<isDebug>" />
</application>

不同于“android:versionName”,“BUGLY_APP_VERSION”配置的是Bugly平台的APP版本号。

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.

 

MultiDex Notes

If MultiDex is used, it is recommended multiDexKeepFileto put the Bugly class into the main Dex through Gradle's " " configuration, etc. It is also recommended to actively load the non-main dex in Applicationthe " " method of the class :attachBaseContext

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

 The above is the access to Bugly. We can write a bug to make the program crash, and we can see the specific error information in the Bugly crash analysis in about a minute. So what should we do if we want to send these crash information to developers in real time? Bugly provides a feature as shown in the figure:

After binding WeChat here, Bugly will count the exceptions within an hour and send them to the person who binds the user. The above is the process of Bugly's access and exception statistics reporting. If you don't understand, you can leave me a comment.

Guess you like

Origin blog.csdn.net/weitao_666/article/details/97920161