您的位置:首页 > 移动开发 > Android开发

Android R.java resource's Ids Non-constant Fields in Case Labels

2016-11-22 14:07 1691 查看
Non-constant Fields in Case Labels

In a regular Android project, constants in the resource R class are declared like this:

public static final int main=0x7f030004;

However, as of ADT 14, in a library project, they will be declared like this:

public static int main=0x7f030004;

In other words, 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.

The reason the fields are no longer final is that it means that the library jars can be compiled once and reused directly in other projects. As well as allowing distributing binary version of library projects (coming in r15), this makes for much faster builds.

the switch statement requires all the case labels, such as R.id.button1, to be constant at compile time(such that the values can be directly copied into the .class files).

ref:
http://tools.android.com/tips/non-constant-fields
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android adt resource
相关文章推荐