How to fix R.string errors when converting to library with ADT14+ android

1k Views Asked by At

I am trying to convert my application project to library, I am getting errors like

resDialogTitle = R.string.crash_dialog_title,

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

They are used in 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;

How to fix this?

1

There are 1 best solutions below

4
On

In ACRA, since ADT 14, R fields are not constants in library project. 2 solutions:

  1. Declare R.string.crash_dialog_text in the app that uses library
  2. You can dynamically set these with ACRA.getConfig():

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

eg:

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

Remember to call ACRA.init(this); in your onCreate() method.

You can set all the fields you need this way. Check here.