@ + android:id有合法用途吗? [英] Is there any legitimate use for @+android:id?

查看:105
本文介绍了@ + android:id有合法用途吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我将android工具升级到最新版本以在 API21 上运行后,尝试编译我的项目导致以下错误:

After I upgraded my android tools to latest version to work on API21, trying to compile my project resulted in the following error:

  • update_languages_button_preference_layout.xml:2:注意:您是要使用 @ + id 代替 @ + android:id 吗?
  • update_languages_button_preference_layout.xml:2:错误:为外部程序包android创建资源:id/layout.
  • update_languages_button_preference_layout.xml:2:错误:错误:找不到与给定名称匹配的资源(在'id',值为'@ + android:id/layout').
  • update_languages_button_preference_layout.xml:2: note: did you mean to use @+id instead of @+android:id?
  • update_languages_button_preference_layout.xml:2: error: creating resource for external package android: id/layout.
  • update_languages_button_preference_layout.xml:2: error: Error: No resource found that matches the given name (at 'id' with value '@+android:id/layout').

问题似乎出在android:id="@+android:id/layout"行:用 @ + id 代替 @ + android:id 足以编译并正常运行项目

The problem seems to be the line android:id="@+android:id/layout": replacing @+android:id by @+id was enough to be able to compile and run the project normally.

但是,快速搜索整个代码库会发现项目中使用构造android:id="@+android:id/...的其他几个位置.这些显然并没有阻止项目通过所有测试,即使我不能保证它们都仍在使用中.

However, a rapid search through the whole codebase revealed a few other locations in the project where the construction android:id="@+android:id/... is used. These apparently didn't prevent the project from passing all tests, even if I can't assure they are all still in use.

  • android:id="@+android:id是否有合法用途,可以证明将那些引用保留在我们的xml文件中,而不是全部替换为@+id?

  • Is there any legitimate use of android:id="@+android:id that would justify leaving those references in our xml files, and not replacing them all by @+id?

为什么它们没有引发与第一个文件相同的错误?

Why didn't they raise the same error as the first file did?

推荐答案

否,您应该从不在您的应用中使用@ + android:id. android名称空间是为框架保留的.对于应用程序来说,这从来都不是安全的,现在会产生编译错误.

No, you should never use @+android:id in your app. The android namespace is reserved for the framework. This has never been safe for an app to use and will now generate a compile error.

在一些背景下,在android名称空间中生成新ID会将其放置在现有android名称空间ID之后的未使用空间中.在框架中添加新的ID之前,此方法将正常工作,此时您的内部ID将与实际的框架ID重叠,并引起奇怪的问题.

For a little background, generating new IDs within the android namespace will put them in the unused space after the existing android namespace IDs. This will work fine until new IDs are added in the framework, at which point your internal ID will overlap with an actual framework ID and cause weird issues.

对于其他实例,这些实例也应该产生错误. AAPT中可能存在错误.无论如何,您应该从资源中删除所有@ + android实例.

As for the other instances, those should be generating errors as well. It's possible that there is a bug in AAPT. Regardless, you should remove all instances of @+android from your resources.

这篇关于@ + android:id有合法用途吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆