android|BugLy统计跟踪错误日志信息热更新

最近接触到了这个东西,试着看官方文档,简单的集成了一下,发现超级好用啊,以后发布的apk,出现的错误信息,可以远程进行监听统计,及时修改bug,大家赶紧入手吧,值得拥有,功能特别强大,而且这个东西集成起来非常的简单,详情大家去官网看官方的sdk吧,比我这个详细
运行效果图:
android|BugLy统计跟踪错误日志信息热更新
文章图片


【android|BugLy统计跟踪错误日志信息热更新】1.添加依赖

apply plugin: 'com.android.application'android { compileSdkVersion 28 defaultConfig { applicationId "com.example.admin.ztest" minSdkVersion 15 targetSdkVersion 28 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" ndk{ //设置支持so库 abiFilters "armeabi" } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } }dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support.constraint:constraint-layout:1.1.3' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' //其中latest.release指代最新Bugly SDK版本号,也可以指定明确的版本号,例如2.1.9 implementation 'com.tencent.bugly:crashreport:latest.release' //其中latest.release指代最新Bugly NDK版本号,也可以指定明确的版本号,例如3.0 implementation 'com.tencent.bugly:nativecrashreport:latest.release' }

2.清单文件添加权限:

3.新建MyApplication ,并且在清单文件添加
package com.example.admin.ztest; import android.app.Application; import android.content.Context; import android.os.Process; import android.text.TextUtils; import com.tencent.bugly.crashreport.CrashReport; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; /** * Created by wrs on 2019/5/21,14:28 * projectName: Ztest5 * packageName: com.example.admin.ztest */ public class MyApplication extends Application {@Override public void onCreate() { super.onCreate(); Context context = getApplicationContext(); //获取当前包名 String packageName = context.getPackageName(); //获取当前进程名 String processName = getProcessName(Process.myPid()); //设置是否为上报进程 CrashReport.UserStrategy strategy = new CrashReport.UserStrategy(context); strategy.setUploadProcess(processName == null || processName.equals(packageName)); //初始化Bugly //context ,APPID千万注意第三个参数 当你用手机连接调试的时候 设置true 可以在logcat看到将要上传的信息 //当你打包发布的时候 一定要修改为false 这样日志才可以上传服务器,在后台可以看到统计的信息 CrashReport.initCrashReport(getApplicationContext(), "587edb0a5d", false); }/** * * 获取进程号对应的进程名 * * // @param pid 进程号 * * @return 进程名 */ private String getProcessName(int pid) { BufferedReader reader = null; try { reader = new BufferedReader(new FileReader("/proc/" + pid + "/cmdline")); String processName = reader.readLine(); if (!TextUtils.isEmpty(processName)) { processName = processName.trim(); } return processName; } catch (Throwable throwable) { throwable.printStackTrace(); } finally { try { if (reader != null) { reader.close(); } } catch (IOException e) { e.printStackTrace(); } } return null; }}

4.主界面,我故意写了两个常见的错误,方便测试,两个按钮,一点击就崩溃,button2中textview没有绑定控件,button3中没有在清单文件注册新建的activity
import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.TextView; import com.tencent.bugly.crashreport.CrashReport; public class MainActivity extends AppCompatActivity { // 官方地址: https://bugly.qq.com/docs/user-guide/instruction-manual-android/?v=20180709165613 private TextView tv_button2; private Button button2; private Button button3; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button2 = findViewById(R.id.button2); button3 = findViewById(R.id.button3); button2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { tv_button2.setText("点击了测试按钮"); } }); button3.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(getApplicationContext(), TwoActivity.class)); } }); } }


    推荐阅读