如何在本地搭建Android应用Crash跟踪系统-ACRA

最近玩了一把ACRA:Application Crash Report For Android

简单说,就是把Android App产生的Crash日志自动发送自己搭建的平台:

是参考这篇文章折腾的:https://testerhome.com/topics/3982 其中crash demo app代码截图不全,可以同时参考http://blog.csdn.net/chen52671/article/details/44751347
(官方文档:https://github.com/ACRA/acralyzer/wiki/setup

具体步骤不再复制粘贴,这里说下问题:

配置本地数据库
现在我们要安装一个acro-storage(Acralyzer的存储端)。通过右侧>的菜单,点击Replicator(复制器),并填写表单的from Remote >Database和from Remote Database类似如下所示:

from Remote Database: http://get.acralyzer.com/distrib-acra-storage

to Local Database: acra-myapp
然后点击Replicate,等待它完成。

这一步一直在转圈loading,后台日志报错:

[info] [<0.132.0>] 192.168.1.2 - - POST /_replicate 500
[error] [<0.132.0>] httpd 500 error response:
{“error”:”timeout”}


怀疑需要翻墙,最近一段时间(20171018)翻墙工具很难用,找遍新工具即使能翻墙速度也很慢,还是报这个错误。

无奈,放弃Replicate Remote Database,参考 EXPERT MODE - manual install from sources
https://github.com/ACRA/acralyzer/wiki/manual-setup
这里需要couchapp, 安装参考:https://github.com/couchapp/couchapp 注意Mac下安装可能因为SIP报错,需要开机时按Command+R(直到出现苹果标志)进入Recovery Mode,关闭它csrutil disable (恢复SIP机制csrutil enable)

另外,使用最新的acra jar包,平台怎么都没日志,降了个老版本,终于有报告了compile 'ch.acra:acra:4.5.0',有时间再抽空看下新版本须新用法?

附,崩溃DemoApp代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tracenote.myapplication">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:name=".CrashApp"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>
</manifest>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import android.content.Context;
import android.app.Application;

import org.acra.ACRA;
import org.acra.ReportingInteractionMode;
import org.acra.annotation.ReportsCrashes;
import org.acra.sender.HttpSender;


@ReportsCrashes(
formKey = "",
// formUri = "https://192.168.1.2:5984/acra-myapp/_design/acra-storage/_update/report",
// reportType = org.acra.sender.HttpSender.Type.JSON,
// httpMethod = org.acra.sender.HttpSender.Method.PUT,
// formUriBasicAuthLogin="tester",
// formUriBasicAuthPassword="111111",
// // Your usual ACRA configuration
// mode = ReportingInteractionMode.TOAST
//// resToastText = R.string.crash_toast_text

httpMethod = HttpSender.Method.PUT,
reportType = HttpSender.Type.JSON,
formUri = "http://192.168.1.2:5984/acra-myapp/_design/acra-storage/_update/report",
formUriBasicAuthLogin = "tester",
formUriBasicAuthPassword = "111111"
)

public class CrashApp extends Application {

// @Override
// protected void attachBaseContext(Context base) {
// super.attachBaseContext(base);
//
// }

@Override
public void onCreate() {
super.onCreate();
ACRA.init(this);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
TextView aaa;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// Integer.parseInt("aa");
// }
// });
int a = 0 / 0;
aaa.setText("aaaaa");

}
}

一些无用代码注释没有花时间去剔除,直接粘过来了。