我正在尝试将我的应用程序项目转换为库,但出现类似这样的错误
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个解决方案:
- 在使用库的应用中声明 R.string.crash_dialog_text
- 你可以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/