"Android Side" code packaged into JAR package/aar form

Source: Internet
Author: User

The Android side code is packaged into jar packages and AAR forms:

First, what is the difference between the form of the jar package and the Aar form?

1. File address generated after packaging:

*.jar: library/build/intermediates/bundles/debug (release)/classes.jar

*.aar: library/build/outputs/aar/libraryname.aar

The difference: The jar package contains only the classes file and does not contain the resource file; AAR contains not only the classes file, but also the resource file

Also, this can be published to the MAVEN library, and the user can obtain the latest AAR file directly by changing the version number.

There is an article that is good, but for more detailed content may be a little bit, resulting in the pit, specific chain interview: http://www.voidcn.com/blog/q610098308/article/p-6059440.html

Then, the packaging of the jar package and the specific use after the final hit

The first directory you need to go to is:

And then here it is: first go to the home directory-build-intermediates-classes-debug directory, directly call the jar CVF generated jar package name to add the. class file

Specifically as shown above: Jar CVF Classes.jar com/ganji/android/leakuploadservice* Com/ganji/android/ Uploadthread.class, where Classes.jar represents the name of the jar package to be generated, followed by com/ganji/android/leakuploadservice* Represents the class file to be added (there may be leakuploadservice.class, if there is an intrinsic function, there may be a form of leakuploadservice$1.class, which can be matched by * as a wildcard character), If more than one file can be separated by adding a space, it is similar to the above format, jar CVF Classes.jar a.class b.class c.class

Then you will be in the debug directory to generate the jar package you need, if you need to configure the version number, then query the relevant information to supplement

Finally, the specific use of the AAR package and the final hit:

The AAR form is packaged in the Android project first through the File-new-new Module

Then choose:

You can then change the name of the module to what you want, such as test:

The structure of this test module for this Android library that you see later is this:

Then own the need, under the java-main will need to eventually build into the AAR package file put in, and then here remember, to put Androidmanifest.xml in the file, will android:label= "@string/app_name" This item is removed, otherwise the app will encounter a conflict (and other app's own Androidmanifest.xml file) when calling this, and if you need to use the Androidmanifest.xml file.

After Build-rebuild project, compiling the entire project will automatically generate the AAR package, in the following way: This directory of the new Module-build-outputs-aar, as shown in the figure below:

——————————————————————————————————————————》》》

After the AAR package is finished, it is the other app that uses this AAR file, first, copy the Aar file to the Libs directory, and then configure the dependencies file in the Build.gradle of the Project home directory, for example:

Compile (name: ' test-1.0 ', ext: ' AAR '), this test-1.0 is the name that is imported into Libs, the name of the AAR generated above is actually modifiable, and the complete Build.gradle file is as follows:

Apply plugin: ' com.android.application ' repositories {flatdir {dirs ' libs '}//introduced aar}dependencies {compile Filetre E (include: ' *.jar ', dir: ' Libs ') compile (name: ' leakupload-1.0 ', ext: ' aar ')}android {compilesdkversion Android_build        _sdk_version as int buildtoolsversion ' 21.1.2 ' compileoptions {encoding "UTF-8"} defaultconfig {        Enabling Multidex support. ApplicationID "Com.ganji.mytest"} lintoptions {Checkreleasebuilds false abortonerror false} D        exoptions {Jumbomode = True javamaxheapsize "2g"//predexlibraries = false} buildtypes { Debug {signingconfig Signingconfigs.release} release {Signingconfig signingconfi Gs.release//Signature shrinkresources True//Remove Unused resources minifyenabled true//confuse, remove unused classes Proguard Files getdefaultproguardfile (' proguard-android.txt '), ' Proguard.cfg '}}}

Then: will prompt sync now, or directly click: This button, click on the synchronization, will be the content of this AAR synchronization, in the code in the Java-main import this AAR, import correct code error will disappear, The structure of this AAR file also appears in the external libraries.

The structure of the AAR appears below: Then the description is added successfully, the specific debugging and use is something

"Android Side" code packaged into JAR package/aar form

Related Article

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.