Android的库项目无法ACRA使用,由于其资源标识符不是最终场了 [英] Android Library Projects could not be used with ACRA due to their resources identifiers not being final fields anymore

查看:497
本文介绍了Android的库项目无法ACRA使用,由于其资源标识符不是最终场了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从ADT网站:

常量不是最终的库项目。这样做的原因
  很简单:当多个库项目相结合,实际
  田野(必须是唯一的)的价值可能会发生冲突。 ADT之前
  14,所有的领域是决赛,所以作为结果,所有的图书馆都必须有
  他们所有的资源和相关的Java code编译随着
  每当他们被用于主体工程。这是不好的表现,
  因为它使建立非常缓慢。它还prevented分发库
  这不包括源$ C ​​$ C项目,限制了使用范围
  库项目。

The constants are not final in a library project. The reason for this is simple: When multiple library projects are combined, the actual values of the fields (which must be unique) could collide. Before ADT 14, all fields were final, so as a result, all libraries had to have all their resources and associated Java code recompiled along with the main project whenever they were used. This was bad for performance, since it made builds very slow. It also prevented distributing library projects that didn't include the source code, limiting the usage scope of library projects.

这是解释这里

所以,为了解决这个问题,我用 -

So, in order to fix this, I used -

int id = view.getId();
if (id == R.id.button1) {
    action1();
} else if (id == R.id.button2) {
    action2();
} else if (id == R.id.button3) {
    action3();
}

而不是 -

    int id = view.getId();

    switch (id) {
    case R.id.button1:
        action1();
        break;
    case R.id.button2:
        action2();
        break;
    case R.id.button3:
        action3();
        break;
}

不过,我有一个类全球国际,我不能够解决这些错误的一样。

But I have a class GlobalData and I am not able to fix these errors for the same.

code -

错误说 -

有关注释属性的值 ReportsCrashes.resDialogText 必须是一个常量前pression当我将光标指向错误在 R.string .crash_dialog_text

The value for annotation attribute ReportsCrashes.resDialogText must be a constant expression when I point the cursor to error at R.string.crash_dialog_text.

推荐答案

您必须动态地添加这些参数的onCreate()应用程序类如下 -

You have to add those parameters dynamically onCreate() in the application class as follows-

public class GlobalData extends Application {
@Override
        public void onCreate() {

            ACRAConfiguration config = ACRA.getConfig();
            config.setMailTo("abc@test.com");
            config.setResDialogIcon(android.R.drawable.ic_dialog_info);
            config.setResDialogText(R.string.crash_dialog_text);
            config.setResDialogTitle(R.string.crash_dialog_title);
            config.setResDialogCommentPrompt(R.string.crash_dialog_comment_prompt);
            config.setResDialogOkToast(R.string.crash_dialog_ok_toast);

            try
            {
                config.setMode(ReportingInteractionMode.DIALOG);
            }
            catch (ACRAConfigurationException e)
            {
                e.printStackTrace();
                return;
            }

            ACRA.setConfig(config);

            ACRA.init(this);
            super.onCreate();
    }
}

这篇关于Android的库项目无法ACRA使用,由于其资源标识符不是最终场了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆