gpt4 book ai didi

Android 资源 ID 突然不是最终的,switch() 坏了

转载 作者:IT老高 更新时间:2023-10-28 23:21:49 30 4
gpt4 key购买 nike

前言:这个问题已经过时了,它是在首选的 Android 开发环境是带有 Android 插件的 Eclipse 时编写的。


我有一段时间有一个 Java Android 项目。今天,我将 Android 开发工具更新到了 Google 的最新版本。项目崩溃了——我收到一堆“case 表达式必须是常量表达式”的编译错误消息。

事实证明,现在生成的 R.java 文件有所不同。以前,它会有一堆

public static final int MyID=0x12340000;

声明;现在,它看起来(在清理/重建之后)是这样的:

public static int MyID=0x12340000;

final 不见了。所以我所有的资源 ID 开关(我有几个)都是错误的。请问怎么了?只有我吗?这里的理由是什么?它在任何地方都有记录吗?我可以以某种方式将 final 带回来吗?

最佳答案

这发生在昨天,当 SDK/ADT 14 发布时:

As of ADT 14, resource constants in library projects are no longer final. This is explained in greater detail in http://tools.android.com/tips/non-constant-fields

ADT 14 提供了一个快速修复:http://tools.android.com/recent/switchstatementconversion

引用理由:

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 突然不是最终的,switch() 坏了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7840914/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com