xCrash 能为安卓 APP 提供捕获 java 崩溃,native 崩溃和 ANR 的能力。不需要 root 权限或任何系统权限。xCrash 能在 App 进程崩溃或 ANR 时,在你指定的目录中生成一个 tombstone 文件(格式与安卓系统的 tombstone 文件类似)。[外链图片转存失败(img-9ORrYjH5-1568958815207)(https://upload-images.jianshu.io/upload_images/15679108-7612516abec07e53?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)]
xCrash 已经在 爱奇艺 的很多安卓 APP(包括爱奇艺视频)中被使用了很多年。
[外链图片转存失败(img-SmtCv1qX-1568958815208)(https://upload-images.jianshu.io/upload_images/15679108-9ce4d26b3ba2a84c?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)]
[外链图片转存失败(img-8L5Reoue-1568958815210)(https://upload-images.jianshu.io/upload_images/15679108-0d2f95206772b3f5?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)]
[外链图片转存失败(img-uGBJOnzv-1568958815210)(https://upload-images.jianshu.io/upload_images/15679108-48d8be4c65b582fa?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)]
1. 增加依赖[外链图片转存失败(img-qDfRS5if-1568958815211)(https://upload-images.jianshu.io/upload_images/15679108-271ab467e9492cfc?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)]
2. 指定一个或多个你需要的 ABI。[外链图片转存失败(img-v92N1Lzf-1568958815211)(https://upload-images.jianshu.io/upload_images/15679108-18e0ab6ab3e1752f?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)]
**3. 初始化 xCrash。**Java[外链图片转存失败(img-Kfx1C5S8-1568958815212)(https://upload-images.jianshu.io/upload_images/15679108-c984a8b4224c8e11?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)]
Kotlin[外链图片转存失败(img-qHURnf6S-1568958815213)(https://upload-images.jianshu.io/upload_images/15679108-fbb3dcc72f001a8f?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)]
Tombstone 文件默认将被写入到 Context#getFilesDir() + “/tombstones” 目录。(通常在: /data/data/PACKAGE_NAME/files/tombstones)在 src/java/xcrash/xcrash_sample 文件夹中,有一个更实际和复杂的示例 APP。
如果你想编译 xCrash 的源码。请按以下步骤进行:1. 下载 Android NDK r16b,设置 PATH 环境变量。2. 编译和复制 native 库。[外链图片转存失败(img-3RQEUlJ4-1568958815213)(https://upload-images.jianshu.io/upload_images/15679108-168ce04faa4be9be?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)]
3. 编译 AAR 库。[外链图片转存失败(img-WrmB5HVg-1568958815214)(https://upload-images.jianshu.io/upload_images/15679108-cbd7dd10027554a1?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)]
更多使用方法可以查看官方文档
https://github.com/iqiyi/xCrash
《如何成为一位Android架构师?(架构视频+面试专题文档+学习笔记)》