以下ACRA配置将空报告发送到我的后端服务器:
@ReportsCrashes(
formKey = "", // This is required for backward compatibility but not used
formUri = "http://myserver/SubmitCrash.aspx",
httpMethod=org.acra.sender.HttpSender.Method.POST,
customReportContent = {ReportField.APP_VERSION_CODE, ReportField.APP_VERSION_NAME, ReportField.ANDROID_VERSION, ReportField.PHONE_MODEL, ReportField.STACK_TRACE, ReportField.LOGCAT },
mode = ReportingInteractionMode.SILENT,
resToastText = R.string.crash_toast_text
)
但是,如果我将ACRA重新配置为将报告发送到电子邮件,它会毫无问题地发送报告,有人知道为什么ACRA会将空报告发送到我的后端服务器吗?
这是我的日志:
04-09 20:57:51.066: E/Trace(661): error opening trace file: No such file or directory (2)
04-10 09:39:49.249: E/Trace(641): error opening trace file: No such file or directory (2)
04-10 09:39:50.270: D/ACRA(641): ACRA is enabled for com.MyApp, intializing...
04-10 09:39:50.352: D/ACRA(641): Looking for error files in /data/data/com.MyApp/files
04-10 09:39:50.660: D/dalvikvm(641): GC_CONCURRENT freed 278K, 10% free 7423K/8199K, paused 28ms+22ms, total 125ms
04-10 09:39:50.680: D/AndroidRuntime(641): Shutting down VM
04-10 09:39:50.680: W/dalvikvm(641): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
04-10 09:39:50.680: E/ACRA(641): ACRA caught a RuntimeException exception for com.MyApp. Building report.
04-10 09:39:50.700: D/ACRA(641): Using default Report Fields
04-10 09:39:51.510: D/dalvikvm(641): GC_CONCURRENT freed 354K, 11% free 7541K/8391K, paused 32ms+26ms, total 143ms
04-10 09:39:52.159: I/ACRA(641): READ_LOGS granted! ACRA can include LogCat and DropBox data.
04-10 09:39:52.199: D/ACRA(641): Retrieving logcat output...
04-10 09:39:52.419: D/dalvikvm(641): GC_CONCURRENT freed 540K, 12% free 7563K/8583K, paused 31ms+9ms, total 98ms
04-10 09:39:52.419: D/dalvikvm(641): WAIT_FOR_CONCURRENT_GC blocked 33ms
04-10 09:39:52.489: D/dalvikvm(641): GC_FOR_ALLOC freed 23K, 12% free 7561K/8583K, paused 64ms, total 64ms
04-10 09:39:52.489: I/dalvikvm-heap(641): Grow heap (frag case) to 7.869MB for 19690-byte allocation
04-10 09:39:52.559: D/dalvikvm(641): GC_FOR_ALLOC freed 12K, 13% free 7567K/8647K, paused 56ms, total 56ms
04-10 09:39:52.569: D/ACRA(641): Writing crash report file 1428658792000.stacktrace.
04-10 09:39:52.709: D/dalvikvm(641): GC_FOR_ALLOC freed 153K, 13% free 7545K/8647K, paused 41ms, total 43ms
04-10 09:39:52.759: D/ACRA(641): About to start ReportSenderWorker from #handleException
04-10 09:39:52.759: D/ACRA(641): Mark all pending reports as approved.
04-10 09:39:52.759: D/ACRA(641): Looking for error files in /data/data/com.MyApp/files
04-10 09:39:52.781: D/ACRA(641): #checkAndSendReports - start
04-10 09:39:52.781: D/ACRA(641): Looking for error files in /data/data/com.MyApp/files
04-10 09:39:52.789: I/ACRA(641): Sending file 1428658792000-approved.stacktrace
04-10 09:39:52.789: D/ACRA(641): Waiting for Toast + worker...
04-10 09:39:53.029: D/dalvikvm(641): GC_FOR_ALLOC freed 197K, 13% free 7574K/8647K, paused 42ms, total 43ms
04-10 09:39:53.110: D/dalvikvm(641): GC_FOR_ALLOC freed 36K, 12% free 7641K/8647K, paused 49ms, total 49ms
04-10 09:39:53.110: I/dalvikvm-heap(641): Grow heap (frag case) to 7.992MB for 65552-byte allocation
04-10 09:39:53.169: D/dalvikvm(641): GC_FOR_ALLOC freed 96K, 14% free 7609K/8775K, paused 50ms, total 51ms
04-10 09:39:53.189: D/ACRA(641): Connect to http://myserver/SubmitCrash.aspx
04-10 09:39:53.519: D/dalvikvm(641): GC_CONCURRENT freed 411K, 14% free 7630K/8775K, paused 21ms+5ms, total 63ms
04-10 09:39:53.519: D/dalvikvm(641): WAIT_FOR_CONCURRENT_GC blocked 43ms
04-10 09:39:53.599: D/ACRA(641): Sending request to http://myserver/SubmitCrash.aspx
04-10 09:39:54.969: D/ACRA(641): #checkAndSendReports - finish
04-10 09:39:55.039: D/ACRA(641): Wait for Toast + worker ended. Kill Application ? true
04-10 09:39:55.059: E/AndroidRuntime(641): FATAL EXCEPTION: main
04-10 09:39:55.059: E/AndroidRuntime(641): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.MyApp/com.MyApp.MainActivity}: java.lang.RuntimeException: This is a crash
04-10 09:39:55.059: E/AndroidRuntime(641): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
04-10 09:39:55.059: E/AndroidRuntime(641): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
04-10 09:39:55.059: E/AndroidRuntime(641): at android.app.ActivityThread.access$600(ActivityThread.java:130)
04-10 09:39:55.059: E/AndroidRuntime(641): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
04-10 09:39:55.059: E/AndroidRuntime(641): at android.os.Handler.dispatchMessage(Handler.java:99)
04-10 09:39:55.059: E/AndroidRuntime(641): at android.os.Looper.loop(Looper.java:137)
04-10 09:39:55.059: E/AndroidRuntime(641): at android.app.ActivityThread.main(ActivityThread.java:4745)
04-10 09:39:55.059: E/AndroidRuntime(641): at java.lang.reflect.Method.invokeNative(Native Method)
04-10 09:39:55.059: E/AndroidRuntime(641): at java.lang.reflect.Method.invoke(Method.java:511)
04-10 09:39:55.059: E/AndroidRuntime(641): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
04-10 09:39:55.059: E/AndroidRuntime(641): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
04-10 09:39:55.059: E/AndroidRuntime(641): at dalvik.system.NativeStart.main(Native Method)
04-10 09:39:55.059: E/AndroidRuntime(641): Caused by: java.lang.RuntimeException: This is a crash
04-10 09:39:55.059: E/AndroidRuntime(641): at com.MyApp.MainActivity.onCreate(MainActivity.java:218)
04-10 09:39:55.059: E/AndroidRuntime(641): at android.app.Activity.performCreate(Activity.java:5008)
04-10 09:39:55.059: E/AndroidRuntime(641): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
04-10 09:39:55.059: E/AndroidRuntime(641): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
04-10 09:39:55.059: E/AndroidRuntime(641): ... 11 more
04-10 09:39:59.819: I/Process(641): Sending signal. PID: 641 SIG: 9
尝试以下Http PUT方法:
httpMethod = org.acra.sender.HttpSender.Method.PUT;
正如logcat所说,您还没有完全配置ACRA。ACRA抱怨您没有提供resDialogText
,这也表明您的ACRA配置的其余部分没有在您的问题中列出。
04-09 20:57:51.066: E/Trace(661): error opening trace file: No such file or directory (2)
04-09 20:57:51.826: W/ACRA(661): Error :
04-09 20:57:51.826: W/ACRA(661): org.acra.ACRAConfigurationException: DIALOG mode: you have to define at least the resDialogText parameters in your application @ReportsCrashes() annotation.
尝试在@ReportsCrashes
中配置这些参数
resDialogText = R.string.crash_dialog_text,
resDialogIcon = R.drawable.dialog_logo,
resDialogTitle = R.string.crash_dialog_title,
resDialogCommentPrompt = R.string.crash_dialog_comment_prompt,
resDialogOkToast = R.string.crash_dialog_ok_toast,
reportType = Type.JSON
希望能有所帮助。