Android Archive Library (aar) vs standard jar

前端 未结 4 2020
青春惊慌失措
青春惊慌失措 2020-11-28 22:22

I\'ve been reading some articles about the new adoption of Gradle as the standard build system for Android apps. Well, coming from standard Java development I usually depend

4条回答
  •  臣服心动
    2020-11-28 22:53

    The statement "The main difference between a Jar and a AAR is that AARs include resources such as layouts, drawables etc." does not correspond to the JAR file specification and therefore is not a truth. According the JAR file specification:

    JAR file is a file format based on the popular ZIP file format and is used for aggregating many files into one. A JAR file is essentially a zip file that contains an optional META-INF directory.

    As you can see, there is no content limitation which forbids including resources such as layouts, drawables etc. in a JAR file. For more detail see article 5.3 "Creation and Loading" of The Java® Virtual Machine Specification.

    So on the question Android Archive Library (aar) vs standard jar. The answer depends on what build tool are you using.

    If you are using Android Studio as a build tool (respectively as a project organizer) you'd definitely better use *.aar files to share encapsulated resources between Android projects. AAR file format is a part of Android Studio build and as it's commented in the other comments here its user interface supports aar format for Android Libraries.

    But except Android Studio the rest of the world does not know what is that thing aar file (artifact). For example, if your Android build is based on Maven the preferred file for resources sharing will be jar because that is the native Maven java project artifact and there is no limitation what to put in the standard jar file. In addition, there is a way to explain Maven any file format, include aar by using lifecycle enhancement with a new component. A simple example is available here How do I create a new packaging type for Maven?

提交回复
热议问题