Bugly - Bugly 基本使用( App 质量追踪平台)

Bugly

1、基本介绍
  1. Bugly 是腾讯推出的 App 质量追踪平台,专门帮开发者发现、定位、解决线上 App 的崩溃、卡顿等问题

    1. 官方网址:https://bugly.qq.com/v2/

    2. 开发文档:https://bugly.qq.com/docs/user-guide/instruction-manual-android/?v=1.0.0

  2. Bugly 优势在于免费、接入简单,适合中小团队快速搭建质量监控体系

2、场景实例
  1. 以前:用户反馈"点了一下就闪退了",开发者复现不了,无从下手

  2. 现在:Bugly 后台直接看到崩溃堆栈、机型、系统版本、操作路径,精准定位到某行代码

3、演示
(1)Setting
  1. 项目级 build.gradle
groovy 复制代码
android {
    defaultConfig {
        ndk {
            abiFilters 'armeabi'
        }
    }
}

...

dependencies {
    implementation 'com.tencent.bugly:crashreport:latest.release'
}
  1. AndroidManifest.xml
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" />
  1. proguard-rules.pro,避免混淆 Bugly

    -dontwarn com.tencent.bugly.**
    -keep public class com.tencent.bugly.**{*;}

(2)Activity
xml 复制代码
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="MainActivity"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/btn_simulate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="模拟一个异常"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView" />
</androidx.constraintlayout.widget.ConstraintLayout>
java 复制代码
public class MainActivity extends AppCompatActivity {

    public static final String TAG = MainActivity.class.getSimpleName();

    private final String[] permissions = {
            Manifest.permission.INTERNET,
            Manifest.permission.ACCESS_NETWORK_STATE,
            Manifest.permission.ACCESS_WIFI_STATE
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        boolean needRequest = false;
        for (String permission : permissions) {
            int re = checkSelfPermission(permission);
            Log.i(TAG, "check ---------- 权限:" + permission + ",授权结果:" + re);
            if (re != PackageManager.PERMISSION_GRANTED) {
                needRequest = true;
                break;
            }
        }

        if (!needRequest) {
            next();
            return;
        }

        ActivityResultLauncher<String[]> activityResultLauncher = registerForActivityResult(
                new ActivityResultContracts.RequestMultiplePermissions(),
                o -> {
                    for (Map.Entry<String, Boolean> stringBooleanEntry : o.entrySet()) {
                        Log.i(TAG, "request ---------- 权限:" + stringBooleanEntry.getKey() + ",授权结果:" + stringBooleanEntry.getValue());
                    }

                    for (boolean granted : o.values()) {
                        if (!granted) {
                            Toast.makeText(this, "未授权权限", Toast.LENGTH_SHORT).show();
                            finish();
                            return;
                        }
                    }

                    next();
                }
        );
        activityResultLauncher.launch(permissions);
    }

    private void next() {
        CrashReport.initCrashReport(getApplicationContext(), "【App ID】", false);

        Button btnSimulate = findViewById(R.id.btn_simulate);

        btnSimulate.setOnClickListener(v -> {
            int i = 10 / 0;
        });
    }
}
相关推荐
葡萄成熟时 !8 小时前
JAVA 常用API学习笔记
java·笔记·学习
Rain的Java大神之路9 小时前
介绍一下分布式事务
java·分布式·后端·spring·spring cloud·架构·springcloud
吴声子夜歌10 小时前
Java面试题——基础(一)
java·开发语言
南城以南溫暖如初14710 小时前
外卖CPS实战指南:从技术选型到运营落地全流程解析
java·spring boot·mysql·架构·vue
傻啦嘿哟11 小时前
英雄联盟皮肤爬虫:爬取全皮肤价格与特效,做比价工具
java·c++·爬虫
码匠许师傅12 小时前
【C++ 面试真题】24. 聊聊 C++ 的时间日期处理
java·c++·面试
mqiqe13 小时前
AgentScope Java 2.0 Agent 状态存储(AgentStateStore)深度解析:构建可恢复、可扩展的智能体运行时
java·运维·网络
zhifou12345613 小时前
java 17升级安装
java·开发语言
用户37215742613513 小时前
如何使用 Java 将 Markdown 转换为 PDF(含自定义设置)
java
用户37215742613513 小时前
如何使用 Java 在 Word 文档中添加和删除水印:分步指南
java