软件出Bug是不可避免的,但要有办法追踪这些Bug。这样才能不断迭代完善软件。Android app bug追踪我用过友盟,Bugly,Sentry。综合对比,Sentry具有接入更方便,UI简洁专业,可以私有化部署的优点。
集成
集成SDK依赖
1 | // Top-level build file |
链接SDK到Sentry(自动)
1 | <application> |
链接SDK到Sentry(手动)
1 | // 一般在application里init |
小项目直接用自动配置就可以,手动配置可以控制dsn,并且在初始化时传一些自定义字段。
测试
1 | public class MyActivity extends AppCompatActivity { |
这时候应该可以在Sentry dashboard上看到一个issue:
开发环境已经可以开始玩耍了。在项目上线后,App打包会进行混淆,这时堆栈信息也是混淆的,有两个办法还原:1,用sdk带的proguard和Release时产生mapping文件还原堆栈信息。2,用Sentry的自动上传功能上传mapping文件,自动反混淆。
设置自动上传
先在项目根目录下创建一个sentry.properties文件:
1 | defaults.project=your-project |
在module的build文件里加上
1 | sentry { |
Auth.token 可以在这里找到,没有的话创建一个。
设置NDK符号文件
在sentry-android 2.0之后是可以捕获Native crash的,不过信息是很不直观的:
这事需要我们上传一些符号文件来反混淆堆栈信息,命令如下:
1 | // --url 是可选的,如果没有私有化部署不需要 |
这时候可以看到JNI函数名称了: