crash反馈-----ACRA使用验证经历

来源:互联网 发布:法甲德佩数据 编辑:程序博客网 时间:2024/06/17 00:38
ACRA是什么?
ACRA是一个用来反馈崩溃日志的android库。

崩溃日志发送到哪里?
ACRA支持多种后台方式,也支持自己定制后台
https://github.com/ACRA/acra/wiki/Backends

我个人是使用email的方式

怎么使用?
官方介绍了网址
https://github.com/ACRA/acra/wiki/BasicSetup

新建Application子类MyApplication,做些初始化

MyApplication.java

@ReportsCrashes(        mailTo = "youEMail@gmail.com", // my email here        mode = ReportingInteractionMode.TOAST,        resToastText = R.string.crash_toast_text)public class MyApplication extends Application {    @Override    public void onCreate() {        super.onCreate();        ACRA.init(this);    }}

AndroidManifest.xml需要修改两点
1. 申请网络权限
2. 重定向Application为MyApplication

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

    <application        android:name="MyApplication"        android:allowBackup="true"        android:icon="@drawable/ic_launcher"        android:label="@string/app_name"        android:theme="@style/AppTheme" >...    </application>

混淆后是否也能正确反馈崩溃堆栈呢?
混淆后也可以使用,但是需要对混淆配置做些修改。
    buildTypes {        release {            minifyEnabled true            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'        }    }

配置文件为app目录下的文件proguard-rules.pro

#====================================#ACRA specifics# Restore some Source file names and restore approximate line numbers in the stack traces,# otherwise the stack traces are pretty useless-keepattributes SourceFile,LineNumberTable# ACRA needs "annotations" so add this... # Note: This may already be defined in the default "proguard-android-optimize.txt"# file in the SDK. If it is, then you don't need to duplicate it. See your# "project.properties" file to get the path to the default "proguard-android-optimize.txt".-keepattributes *Annotation*# Keep all the ACRA classes-keep class org.acra.** { *; }

编译release版本,反编译后用jdgui查看,验证了下,确实混淆了。



安装后,使用时产生的崩溃日志

USER_COMMENT=nullANDROID_VERSION=4.3APP_VERSION_NAME=1.0BRAND=samsungPHONE_MODEL=GT-N7102CUSTOM_DATA=STACK_TRACE=java.lang.NullPointerExceptionat com.example.jacksonke.configchangedemo.MainActivity$PlaceholderFragment.makeCrash(MainActivity.java:107)at com.example.jacksonke.configchangedemo.b.doClick(MainActivity$PlaceholderFragment$$ViewBinder.java:28)at butterknife.internal.DebouncingOnClickListener.onClick(DebouncingOnClickListener.java:22)at android.view.View.performClick(View.java:4475)at android.view.View$PerformClick.run(View.java:18786)at android.os.Handler.handleCallback(Handler.java:730)at android.os.Handler.dispatchMessage(Handler.java:92)at android.os.Looper.loop(Looper.java:137)at android.app.ActivityThread.main(ActivityThread.java:5528)at java.lang.reflect.Method.invokeNative(Native Method)at java.lang.reflect.Method.invoke(Method.java:525)at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1209)at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1025)at dalvik.system.NativeStart.main(Native Method)

能正确的定位到崩溃点。


具体文档可查看
https://github.com/ACRA/acra/wiki/ProGuard



0 0