ACRA 无法将 customHttpSender 发送到 Acrarium
ACRA can't send customHttpSender to Acrarium
我需要修改发送到 Acrarium 的报告,所以我使用 HttpSender。我尝试使用 ReportSender 而不是 HttpSender,但结果是一样的:报告未发送到 Acrarium。使用默认设置(没有 SenderFactory::class)它工作正常。
这是我的应用程序class:
@AcraCore(
buildConfigClass = BuildConfig::class,
reportContent = [ReportField.APP_VERSION_NAME, ReportField.ANDROID_VERSION, ReportField.PHONE_MODEL, ReportField.CUSTOM_DATA, ReportField.STACK_TRACE],
reportSenderFactoryClasses = [SenderFactory::class]
)
@AcraHttpSender(
uri = "http://localhost:port/report",
basicAuthLogin = "..........",
basicAuthPassword = "..........,
httpMethod = HttpSender.Method.POST
)
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
ACRA.init(this)
}
}
我的 CustomHttpSender:
class CustomSender(config: CoreConfiguration, method: Method = Method.POST, type: StringFormat? = null)
: HttpSender(config, method, type) {
override fun send(context: Context, report: CrashReportData) {
try {
report.put(
ReportField.PHONE_MODEL,
report.getString(ReportField.PHONE_MODEL) + getAdditionalInfo()
)
println("Report: \n" + report.getString(ReportField.PHONE_MODEL))
// sendHttpRequests(config, context, mMethod, mType.matchingHttpContentType, login, password, httpConfig.connectionTimeout,
// httpConfig.socketTimeout, httpConfig.httpHeaders, reportAsString, reportUrl, uris)
Log.e("YourOwnSender", report.toJSON())
} catch (e: Exception) {
e.printStackTrace()
}
}
override fun sendHttpRequests(configuration: CoreConfiguration, context: Context, method: Method,
contentType: String, login: String?, password: String?, connectionTimeOut: Int, socketTimeOut: Int,
headers: MutableMap<String, String>?, content: String, url: URL, attachments: MutableList<Uri>
) {
}
fun getAdditionalInfo(): String {
return " ABC-001"
}
}
我的发件人工厂:
@AutoService(ReportSenderFactory::class)
class SenderFactory: ReportSenderFactory {
override fun create(context: Context, config: CoreConfiguration): ReportSender {
return CustomSender(config, HttpSender.Method.POST, StringFormat.JSON)
}
override fun enabled(config: CoreConfiguration): Boolean {
return true
}
}
logcat在使用默认设置和CustomSender之间是一样的:
2021-02-26 10:55:05.163 1448-1448/? I/xample.acrates: Late-enabling -Xcheck:jni
2021-02-26 10:55:05.330 1448-1448/? E/xample.acrates: Unknown bits set in runtime_flags: 0x8000
2021-02-26 10:55:05.628 1448-1448/com.example.acratest I/ACRA: ACRA is enabled for com.example.acratest, initializing...
2021-02-26 10:55:05.774 1448-1448/com.example.acratest E/xample.acrates: Invalid ID 0x00000000.
2021-02-26 10:55:05.853 1448-1448/com.example.acratest W/xample.acrates: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
2021-02-26 10:55:05.854 1448-1448/com.example.acratest W/xample.acrates: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
2021-02-26 10:55:05.952 1448-1525/com.example.acratest E/xample.acrates: Invalid ID 0x00000000.
2021-02-26 10:55:05.999 1448-1495/com.example.acratest I/Adreno: QUALCOMM build : 4a00b69, I4e7e888065
Build Date : 04/09/19
OpenGL ES Shader Compiler Version: EV031.26.06.00
Local Branch : mybranche95ae4c8-d77f-f18d-a9ef-1458d0b52ae8
Remote Branch : quic/gfx-adreno.lnx.1.0
Remote Branch : NONE
Reconstruct Branch : NOTHING
2021-02-26 10:55:05.999 1448-1495/com.example.acratest I/Adreno: Build Config : S L 8.0.5 AArch64
2021-02-26 10:55:06.003 1448-1495/com.example.acratest I/Adreno: PFP: 0x005ff110, ME: 0x005ff066
2021-02-26 10:55:06.020 1448-1495/com.example.acratest W/Gralloc3: mapper 3.x is not supported
选项卡不同 运行。
没有SenderFactory::class的默认设置:
使用 SenderFactory:
如何将修改后的报告发送到 Acrarium?
----------------编辑----------------
我只需要添加一行:
super.send(context, report)
override fun send(context: Context, report: CrashReportData) {
try {
report.put(
ReportField.PHONE_MODEL,
report.getString(ReportField.PHONE_MODEL) + getAdditionalInfo()
)
Log.e("YourOwnSender", report.toJSON())
super.send(context, report)
} catch (e: Exception) {
throw ReportSenderException(
"Error while sending JSON report via Http POST",
e
)
}
}
而且我不需要重写有趣的 sendHttpRequests。
重写方法时始终调用 super。
您的 Sender 重写了两个方法而不调用超级方法,实际上删除了功能。
您还需要在注册自己的时禁用默认发件人。
我需要修改发送到 Acrarium 的报告,所以我使用 HttpSender。我尝试使用 ReportSender 而不是 HttpSender,但结果是一样的:报告未发送到 Acrarium。使用默认设置(没有 SenderFactory::class)它工作正常。
这是我的应用程序class:
@AcraCore(
buildConfigClass = BuildConfig::class,
reportContent = [ReportField.APP_VERSION_NAME, ReportField.ANDROID_VERSION, ReportField.PHONE_MODEL, ReportField.CUSTOM_DATA, ReportField.STACK_TRACE],
reportSenderFactoryClasses = [SenderFactory::class]
)
@AcraHttpSender(
uri = "http://localhost:port/report",
basicAuthLogin = "..........",
basicAuthPassword = "..........,
httpMethod = HttpSender.Method.POST
)
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
ACRA.init(this)
}
}
我的 CustomHttpSender:
class CustomSender(config: CoreConfiguration, method: Method = Method.POST, type: StringFormat? = null)
: HttpSender(config, method, type) {
override fun send(context: Context, report: CrashReportData) {
try {
report.put(
ReportField.PHONE_MODEL,
report.getString(ReportField.PHONE_MODEL) + getAdditionalInfo()
)
println("Report: \n" + report.getString(ReportField.PHONE_MODEL))
// sendHttpRequests(config, context, mMethod, mType.matchingHttpContentType, login, password, httpConfig.connectionTimeout,
// httpConfig.socketTimeout, httpConfig.httpHeaders, reportAsString, reportUrl, uris)
Log.e("YourOwnSender", report.toJSON())
} catch (e: Exception) {
e.printStackTrace()
}
}
override fun sendHttpRequests(configuration: CoreConfiguration, context: Context, method: Method,
contentType: String, login: String?, password: String?, connectionTimeOut: Int, socketTimeOut: Int,
headers: MutableMap<String, String>?, content: String, url: URL, attachments: MutableList<Uri>
) {
}
fun getAdditionalInfo(): String {
return " ABC-001"
}
}
我的发件人工厂:
@AutoService(ReportSenderFactory::class)
class SenderFactory: ReportSenderFactory {
override fun create(context: Context, config: CoreConfiguration): ReportSender {
return CustomSender(config, HttpSender.Method.POST, StringFormat.JSON)
}
override fun enabled(config: CoreConfiguration): Boolean {
return true
}
}
logcat在使用默认设置和CustomSender之间是一样的:
2021-02-26 10:55:05.163 1448-1448/? I/xample.acrates: Late-enabling -Xcheck:jni
2021-02-26 10:55:05.330 1448-1448/? E/xample.acrates: Unknown bits set in runtime_flags: 0x8000
2021-02-26 10:55:05.628 1448-1448/com.example.acratest I/ACRA: ACRA is enabled for com.example.acratest, initializing...
2021-02-26 10:55:05.774 1448-1448/com.example.acratest E/xample.acrates: Invalid ID 0x00000000.
2021-02-26 10:55:05.853 1448-1448/com.example.acratest W/xample.acrates: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
2021-02-26 10:55:05.854 1448-1448/com.example.acratest W/xample.acrates: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
2021-02-26 10:55:05.952 1448-1525/com.example.acratest E/xample.acrates: Invalid ID 0x00000000.
2021-02-26 10:55:05.999 1448-1495/com.example.acratest I/Adreno: QUALCOMM build : 4a00b69, I4e7e888065
Build Date : 04/09/19
OpenGL ES Shader Compiler Version: EV031.26.06.00
Local Branch : mybranche95ae4c8-d77f-f18d-a9ef-1458d0b52ae8
Remote Branch : quic/gfx-adreno.lnx.1.0
Remote Branch : NONE
Reconstruct Branch : NOTHING
2021-02-26 10:55:05.999 1448-1495/com.example.acratest I/Adreno: Build Config : S L 8.0.5 AArch64
2021-02-26 10:55:06.003 1448-1495/com.example.acratest I/Adreno: PFP: 0x005ff110, ME: 0x005ff066
2021-02-26 10:55:06.020 1448-1495/com.example.acratest W/Gralloc3: mapper 3.x is not supported
选项卡不同 运行。
没有SenderFactory::class的默认设置:
使用 SenderFactory:
如何将修改后的报告发送到 Acrarium?
----------------编辑----------------
我只需要添加一行:
super.send(context, report)
override fun send(context: Context, report: CrashReportData) {
try {
report.put(
ReportField.PHONE_MODEL,
report.getString(ReportField.PHONE_MODEL) + getAdditionalInfo()
)
Log.e("YourOwnSender", report.toJSON())
super.send(context, report)
} catch (e: Exception) {
throw ReportSenderException(
"Error while sending JSON report via Http POST",
e
)
}
}
而且我不需要重写有趣的 sendHttpRequests。
重写方法时始终调用 super。
您的 Sender 重写了两个方法而不调用超级方法,实际上删除了功能。
您还需要在注册自己的时禁用默认发件人。