安卓资源ID突然没有最终确定,开关()'ES破卓资、突然、ES、ID

2023-09-05 10:12:18 作者:心已倦了

我有一个Java的Andr​​oid项目一段时间。今天,我已经更新了Android开发工具到谷歌最新的。而该项目打破了 - 我得到了一堆案前pressions必须是恒定的前pressions编译错误信息

I had a Java Android project for a while. Today, I've updated the Android dev tools to the Google's latest. And the project broke - I get a bunch of "case expressions must be constant expressions" compilation error messages.

原来的R.java文件现在正在生成不同。以前,这将有一大堆的

Turns out that the R.java file is being now generated differently. Formerly, it would have a bunch of

public static final int MyID=0x12340000;

报表;现在,它看起来(干净后/重建)是这样的:

statements; now, it looks (after a clean/rebuild) like this:

public static int MyID=0x12340000;

最后走了。所以对我有(我有几个)资源ID的所有开关都错了。发生了什么事,好吗?难道仅仅是我吗?这里有什么道理呢?难道是记录任何地方?我可以带最后回不知何故?

final is gone. So all switches on resource IDs that I had (and I had a few) are wrong. What happened, please? Is it just me? What's the rationale here? Is it documented anywhere? Can I bring final back somehow?

推荐答案

这事昨天,当SDK / ADT 14得到了释放:

This happened about yesterday, when the SDK/ADT 14 got released:

由于ADT 14日,在库项目资源常量不再   最终。这更详细地http://tools.android.com/tips/non-constant-fields

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

有可用的quickfix ADT的14:http://tools.android.com/recent/switchstatementconversion

There's a quickfix available from ADT 14: http://tools.android.com/recent/switchstatementconversion

要由理引用:

在多个库项目相结合,对实际值   字段(它必须是唯一的)可能发生碰撞。 ADT 14,各个领域之前   是最终的,这样一来,所有的图书馆都必须有他们所有的   资源和相关的Java code编译随主   无论他们使用的项目。这是不好的性能,因为   这让建立非常缓慢。它还prevented分发库   这不包括源$ C ​​$ C项目,限制了使用范围   库项目。

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.

的原因的字段不再最后是,它意味着该库罐可被编译一次,并直接在其他项目中重复使用。除了允许分发库项目(即将在R15),这将产生更快的构建。二进制版本

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.