Skip to content

Prefix everything

ZieIony edited this page Oct 25, 2019 · 2 revisions

This is very important, not only if you're making a library, but also if you are using any in your code. Here's a couple of examples, you need to remember:

  • Attribute names should be declared only once and then reused. If you add a declaration of an attribute with the same name, but a different format, AAPT will complain. Google itself is the largest provider of unprefixed, simple attributes added to its Support Libraries.
  • Android build system allows overriding resources by providing your own with the same name and type. Prefix all layouts, values, drawables and other resources to reduce the risk of unintentional resource overriding.
  • Dalvik allowed overriding private methods by specifying methods with matching signatures in child classes. Don't use short, generic names, like init(), because one of the classes in the inheritance chain may override it. This is getting less and less important due to Dalvik being replaced by ART, but still an interesting quirk. Read more here on StackOverflow.
Clone this wiki locally