android - 使用 ADT14+ android 转换为库时如何修复 R.string 错误

标签 android android-library acra

我正在尝试将我的应用程序项目转换为库,但出现类似这样的错误

resDialogTitle = R.string.crash_dialog_title,

The value for annotation attribute ReportsCrashes.resDialogTitle must be a constant expression  

它们在 ACRA header 中使用

@ReportsCrashes(formKey = "--", mode = ReportingInteractionMode.DIALOG, mailTo = "--", customReportContent = {
        ReportField.APP_VERSION_CODE, ReportField.APP_VERSION_NAME,
        ReportField.ANDROID_VERSION, ReportField.PHONE_MODEL,
        ReportField.CUSTOM_DATA, ReportField.STACK_TRACE, ReportField.LOGCAT }
// resToastText = R.string.crash_toast_text, // optional, displayed as soon as
// the crash occurs, before collecting data which can take a few seconds
        resDialogText = getString(R.string.crash_dialog_text),
        resDialogIcon = android.R.drawable.ic_dialog_info, // optional.
// default
// is
// a
// warning
// sign
//resDialogTitle = R.string.crash_dialog_title, // optional. default is your
// application name
resDialogCommentPrompt = R.string.crash_dialog_comment_prompt, // optional. when
// defined, adds
// a user text
// field input
// with this
// text resource
// as a label
resDialogOkToast = R.string.crash_dialog_ok_toast // optional. displays a Toast
// message when the user
// accepts to send a report.
)
public class MainAppClass extends Application {

    private static MainAppClass singleton;

如何解决这个问题?

最佳答案

在 ACRA 中,自 ADT 14 起,R fields are not constants in library project . 2个解决方案:

  1. 在使用库的应用中声明 R.string.crash_dialog_text
  2. 你可以dynamically使用 ACRA.getConfig() 设置这些:

The method ACRA.getConfig() returns an ACRAConfiguration object which provides a setter for each @ReportsCrashes configuration item.

例如:

    ACRA.getConfig().setResDialogText(R.string.crash_dialog_text);

记得在 onCreate() 方法中调用 ACRA.init(this);

您可以通过这种方式设置您需要的所有字段。检查here .

关于android - 使用 ADT14+ android 转换为库时如何修复 R.string 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20739178/

相关文章:

android - 在 Samsung s8 上解析包时出现问题,有什么解决方案吗?

android - 2018年安卓上的相册选图有什么方法?

android - 无法从应用程序项目加载存储在库 (aar) 中的 .so 文件

android - 运行时异常被 ACRA 捕获,不会显示在 Logcat 上

android - 未授予 Android 应用程序中的互联网权限

java - 安卓 : Need help in implementing ACRA

android - PhoneGap - 从当前应用程序启动另一个应用程序

java - 替换其他声明但不存在其他声明?

android - App模块在android studio中消失了

具有依赖关系的 Android 库无法正确解析