3

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: 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').

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.

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.

  • 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?

PLNech
  • 3,087
  • 1
  • 23
  • 52
  • 4
    no, at least `@+android:id/...` you can use `@android:id/...`(without `+`) for special ids like fx: `@android:id/list` for ListFragment/Activity the `@+...` means create the new id, if not exists ... i do not see the point of creating new `android:id` ids – Selvin Oct 27 '14 at 16:16
  • Thank you, indeed that would have been my answer to the first question. However, do you have an idea why **only one** of those references prevented the project to build? – PLNech Oct 27 '14 at 17:32
  • I also face with this issue. Android API 21 does not accept this declaration. I must back to SDK for Android 4.4, and wait till this can be resolved. – Phuong Feb 12 '15 at 09:14
  • @Phuong: what do you mean, "wait till this can be resolved"? The only resolution will be updating erroneous references to use the valid syntax instead. – PLNech Feb 12 '15 at 09:54

2 Answers2

3

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.

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.

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.

alanv
  • 23,966
  • 4
  • 93
  • 80
  • Thank you for your answer. Do you see any reason for the other references not to generate a build error than the possibility that those layouts may not be referenced anymore through the project? – PLNech Oct 27 '14 at 21:44
  • 1
    No, they ought to be generating errors if they are actually being compiled. It may be an AAPT bug. I would strongly recommend fixing them even if they are not generating errors at compile time because are likely to cause issues at run time. – alanv Oct 27 '14 at 22:21
3

Though my comment is very late. I faced same issue today, when updated my eclipse and tools. Changed @+android:id to @+id and it solved my issue.

AndroidDev
  • 2,627
  • 6
  • 29
  • 41
  • Beware of updating potential references through the project that may now be invalid, such as `findViewById(R.android.id.xxx)` that would throw **RuntimeException**s when reached. – PLNech Dec 03 '14 at 16:07