The nine pits that have been trampled in Android development: Notes on the issue of an AAR

Source: Internet
Author: User

Now Android supports the AAR format to publish a module that is available to other people for use.

AAR is actually a zip package for jars and some resource files. Addressed the limitations of past jar packages not sharing resources.


1 to avoid defining internal interfaces as much as possible,

This is actually a programming habit, and the interface interface is best defined independently and avoids being defined inside the class.

Because when you publish an AAR, the internal interface is confused and becomes an external interface outer$innerinterface.

Then the trouble comes, others in the implementation of this class must also be written in the form of XXX implement outer$innerinterface{}. Otherwise, this class is not found.

Want to write XXX implement outer.innerinterface{} is not, because in Outer there is no definition of this innerinterface, after confusion, All of the inner classes are rewritten as external classes that are shaped like outer$inner. including interface, Enum, and so on.

What's worse, you're probably just releasing part of the code for the project as AAR, and the Outer.Inner class or interface you've referenced within your project must be written in outer$inner form, otherwise the runtime cannot find the class. so, in order to avoid unnecessary trouble later, try not to use internal classes, internal interfaces,

Unless you are sure that the code will not be confused, or that all definitions and calls will be involved in confusion.


2 using MAVEN publishing requires that all dependencies be posted to Maven

If you publish multiple AAR, each of which is dependent on each other, then you need to define these dependencies as MAVEN, otherwise the null pointer exception will be reported at compile time when Maven parses an AAR's pom.

The form definition of maven:

Apply plugin: ' maven '
Compile ' com.nineoldandroids:library:2.4.0+ '


The attribute or name defined in 3 res should be prefixed

It is normal for your AAR to define resource files, and resource files are likely to have the same name as other people's resources , and tragically, others may have quoted another AAR as having the same name as you. He cannot modify the name of the AAR resource, just as he cannot modify your AAR resource name. To avoid this embarrassment, it is best to add a prefix to the defined resource path, such as your module shorthand, trademark shorthand, and so on. Avoid conflict, can also make an advertisement, why not.




The nine pits that have been trampled in Android development: Notes on the issue of an AAR

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.