Differences between jar files and AAR files

Source: Internet
Author: User

1. *.jar,jar files are Java Archive file, as implies meaning, its application is related to Java, is a Java document format. Contains only the class file and the manifest file, does not contain the resource file, the slice and so on all res files. Find a jar file, then modify the suffix named ' zip ' or ' rar ' format, then unzip the file and open the Unpacked folder as follows:

Click on the ' COM ' folder and you'll see all the '. class ' files inside.

The Ps:jar file format is based on the popular ZIP file format. Unlike ZIP files, JAR files are not only used for compression and publishing, but are also used to deploy and encapsulate libraries, components, and plug-ins, and can be used directly by tools such as compilers and JVMs. The jar contains special files, such as manifests and deployment descriptors, to indicate how the tool handles a particular JAR. The JAR (Java Archive,java archive) is a platform-independent file format that allows many files to be combined into a single compressed file. The JAR file created for the Java EE application is an EAR file (Enterprise JAR file). The JAR file format offers many advantages and functionality, many of which are traditional compression formats such as ZIP or TAR that are not available. They include: security, reduced download time, transmission platform expansion, packet sealing, package versioning, portability

2. The *.aar,aar (Android Archive) package is a binary archive file for an Android library project. We randomly find an AAR file, then modify the suffix named ' zip ' or ' rar ' format, then unzip the file and open the extracted folder as follows: (the content of each AAR may not be exactly the same, but it will contain androidmanifest.xml, Classes.jar,res,r.txt)

The *.aar file contains all the resources, class, and res resource files.

Second, generate AAR files and jar files.

1. Generate the jar file.

In Android Studio, declare the Gradle script at the beginning of a module

[Plain]View PlainCopy
    1. Apply plugin: ' Com.android.library '
The module is then compiled, and after compilation is completed, it is Build-->intermediates-->bundles-->debug (release)-->classes.jar of module, as shown in:


2. Generate the AAR file.

In Android Studio, declare the Gradle script at the beginning of a module

[Plain]View PlainCopy
    1. Apply plugin: ' Com.android.library '
Then compile the module, which will be completed in the module's Build-->outputs-->aar-->xxxxx.aar, as shown in:

Third, use.

1. *.jar file use.

*.jar files are copied to the Libs directory, eclipse can be imported directly and added to the Androidstudio project:

[Plain]View PlainCopy
    1. dependencies {
    2. Compile Filetree (include: [' *.jar '], dir: ' Libs ')
    3. }
Recompile to complete.

2. *.aar file use.

There are two ways to use the *.aar file, one is to use online (online), and one is to add a local *.aar file. Network load, as long as you know the path of the *.aar file in Maven, is not shown here. Here's a look at how to load the local *.aar file in Android Studio.

(1). Place the AAR file in a file directory, for example, in the Libs directory;

(2). In the app's Build.gradle file, add the following content;

[Plain]View PlainCopy
    1. repositories {
    2. Flatdir {
    3. Dirs ' Libs '
    4. }
    5. }

(3). The AAR file can be conveniently referenced by adding a gradle dependency;

[Plain]View PlainCopy
    1. dependencies {
    2. ...
    3. Compile (name: ' Test ', ext: ' AAR ')
    4. ...
    5. }
At this point, loading the local *.aar file in Android studio ends, isn't it simple! It should be added that if the *.aar file references a package from another MAVEN repository, you need to add a dependency in the Gradle, otherwise it might be reported as "caused By:Java.lang.ClassNotFoundException" when running!

Maybe some friends still have questions, "How to use AAR files in Eclipse", this is not explained here, it is recommended to replace as soon as Android Studio!

Iv. Summary.

Under what circumstances do I use the *.jar file? Under what circumstances do I use the *.aar file?

If you are just a simple class library then use the generated *.jar file;

If you have a UI library that contains resource files such as control layout files and fonts, you can only use the *.aar file.

Differences between jar files and AAR files

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.