爱奇艺视频 APP 使用的 Android native crash + Java exception 捕获方案在 GitHub 开源了

2019-04-11 11:33:09 +08:00
 caikelun

GitHub 地址: https://github.com/iqiyi/xCrash

欢迎 star,issue,PR ~~~


xCrash

xCrash 是一个安卓 APP 的崩溃捕获库。它支持捕获 native 崩溃和 Java 异常。

xCrash 能在 App 进程崩溃时,在你指定的目录中生成一个 tombstone 文件(格式与安卓系统的 tombstone 文件类似)。并且,不需要 root 权限或任何系统权限。

xCrash 已经在 爱奇艺 的很多安卓 APP (包括爱奇艺视频)中被使用了很多年。

特征

捕获 native 崩溃

使用

1. 增加依赖。

dependencies {
    implementation 'com.iqiyi.xcrash:xcrash-android-lib:2.0.5'
}

2. 指定你需要的 ABI(s)。

android {
    defaultConfig {
        ndk {
            abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
        }
    }
}

3. 增加 ProGuard 规则。

-keep class xcrash.NativeCrashHandler {
    native <methods>;
    void callback(...);
}

4. 在 Application#attachBaseContext() 中初始化 xCrash。

public class MyCustomApplication extends Application {

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        
        xcrash.XCrash.init(this);
    }
}

Tombstone 文件默认将被写入到 Context#getFilesDir() + "/tombstones" 目录。(通常在: /data/data/<APP_PACKAGE_NAME>/files/tombstones

src/java/xcrash/xcrash_sample 文件夹中,有一个更实际和复杂的示例 APP。

构建

1. 下载 Android NDK r16b,设置 PATH 环境变量。

2. 编译和安装 native 库。

cd ./src/native/
./build.sh
./install.sh

3. 编译 AAR 库。

cd ./src/java/xcrash/
./gradlew :xcrash_lib:build

贡献

请阅读 xCrash Contributing Guide

许可证

xCrash 使用 MIT 许可证

xCrash 的文档使用 Creative Commons 许可证

5222 次点击
所在节点    Android
2 条回复
waruqi
2019-04-11 13:38:22 +08:00
赞!
jesonyang
2019-04-11 13:46:16 +08:00
bibib

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/554008

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX