android - 资源 ID 在 Android Gradle 插件 5.0 版中将是非最终的,请避免在 switch case 语句中使用它们

标签 android

Android Studio 现在警告这一重大变化即将到来。Resource IDs will be non-final in Android Gradle Plugin version 5.0, avoid using them in switch case statements唯一的其他选项是if/else吗?

最佳答案

每个 Google 都必须使用 if/else: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.

关于android - 资源 ID 在 Android Gradle 插件 5.0 版中将是非最终的,请避免在 switch case 语句中使用它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63290845/

相关文章:

java - 如何从资源目录中读取多个文件

android - 无法在 Android Studio 2.0 中打开项目结构

android - 上下 move ImageView 的动画

java - 在 Recycler Adapter 中获取 Activity onDestroy()

android - 如何保持安卓上的 GPS/定位服务始终开启?

java - Dagger2 看不到在其他模块中定义的带有@Provide 注解的方法。没有 @provides-annotated 方法就无法提供

java - 在 textView 内显示可点击的链接

javascript - 我如何读取android中的屏幕宽度和高度?

android - 如何在android中将录制的男声转换为女声?

android - 如何更改 Android 中微调器控件的下拉箭头箭头?