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
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
相关文章推荐
- Non-constant Fields in Case Labels
- Android NDK: WARNING:jni/Android.mk: non-system libraries in linker flags: -lopencv_java3
- 异常: Unfortunately you can't have non-Gradle Java modules and Android-Gradle modules in one project.
- Unfortunately you can't have non-Gradle Java modules and Android-Gradle modules in one project.
- Resource IDs cannot be used in a switch statement in Android library modules
- Resource IDs cannot be used in a switch statement in Android library modules
- OpenCV4Android:non-system libraries in linker flags: -lopencv_java错误的解决
- Unfortunately you can't have non-Gradle Java modules and Android-Gradle modules in one project.
- Validates using resource IDs in a switch statement in Android library module
- java.lang.RuntimeException: Method setUp in android.test.ApplicationTestCase not mocked. See http://g.co/androidstudio/not-mocked for details.
- Android开发问题之--Validates using resource IDs in a switch statement in Android library module
- Java Tips - How do I declare a constant in Java
- android开发问题:java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected imp
- Android 设置环境出现Java not found in your path的解决办法
- 解决错误ERROR: No suitable Java found. In order to properly use the Android Developer Tools,…
- Android 编译出现Multiple substitutions specified in non-positional format 错误
- How to tacktrace In Android for Java code
- Enable Android progurad in the case of multiple JAR lib
- c++ invoke java in android
- HttpPost works in Java project, not in Android