androidxmlandroid-5.0-lollipopandroid-identifiers

Is there any legitimate use for @+android:id?


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.


Solution

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