The main difference is aar is splitted inside android to jar. If your app will be used only in user app only in android studio then aar is preferred. If you are planning for app to communicate with c/c++ compiled lib.so file jar is preferred.
AAR files can contain Android resources and a manifest file, which allows you to bundle in shared resources like layouts and drawables in addition to Java classes and methods. AAR files can contain C/C++ libraries for use by the app module's C/C++ code.
An AAR file contains a software library used for developing Android apps. It is structurally similar to an . APK file (Android Package), but it allows a developer to store a reusable component that can be used across multiple different apps.
jar JAR file is only used for the Java compiler before deployment on an Android device. It is not bundled with your application. By default, all calls to the provided Android. jar throw exceptions, this allows you to write tests that do not depend on any Android platform behavior.
AAR
files are more similar to Jar
s than to Dll
s for the following reason:
Dll
s can be shared across applications where asAAR
s and jars are packaged in with your app.
AAR
s vs Jar
s:
The main difference between a
Jar
and aAAR
is thatAAR
s include resources such aslayouts, drawables
etc. This makes it a lot easier to create self-contained visual components. For example if you have multiple apps that use the same login screen, withJar
s you could share classes but not the layout, styles, etc., you still had to duplicate them. WithAAR
s everything is bundled in one neat package.
In conclusion, AAR
s are a big step in the right direction.
Note:
Similar attempts were made with apk-lib
s but they are now obsolete as AAR
s are much better.
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?
The citation in the question has nothing common with the current reality. Of course it is possible to use external libraries in Android and there are lots libraries available. Maybe they wanted to say that each application must bundle all libraries it needs, but reusing the library at the build time (static linking) is really not a problem.
.aar
differs from .jar
no more than .jar
differs from .zip
. It has certain concepts on which kind of content should be expected there, but both .jar
and .aar
most often contain compiled classes and they resources. .aar
just specifies that the library is Android specific and has some expected structure, reasonable for such libraries (well, .jar
also has some expected structure).
The view that .aar is only supported by Android studio is also deprecated. Such libraries can be deployed to Maven Central, and tools like gradle can reference them using @aar suffix, for instance:
dependencies {
compile ('io.github.andviane:uncover:2.0.1@aar')
..
}
to reference this Maven central deployment.
JAR vs AAR
JAR
– Java Archive. Contains .class
, java resources
AAR
– Android Archive. Contains classes.jar
, and other Android related files like AndroidManifest.xml, R.txt, proguard.txt, res folder(layout, values, drawable) and others.
Android works with both files jar
and aar
. As a library developer usually aar
is used for sharing Android resources, otherwise - jar
like more lightweight and common way of distributing an artefact.
Since aar
contains jar
you can use it[About]
Difference:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With