Since the company’s project needs to package the complete App into an AAR package and provide it to other cooperative manufacturers for integration and embedding, external manufacturers need to have their own shell engineering and corresponding Application and then call our AAR, which has made a lot of mistakes. Today, WE will first talk about making the complete project into an independent SDK package.

What is an AAR? *. Aar, AAR(Android Arehive) package is a binary archive of Android library projects, aar contains all resources, class, XML layout files, and RES resource files. Notice is all. Jar contains only class files and manifest files, not resource files, such as images, all files in res.

Ii. The steps for packaging a complete project into an AAR are as follows:

1. In the build.gradle directory of App:

A. Change the apply plugin:’com.android. application’ to app plugin:’com.android.library’. Screenshot below:

B. Delete applicationId. The screenshot is as follows:

2. Go to the manifest file and modify the AndroidManifest configuration:

The modified manifest file is shown below:

3. Operate Android Studio in the project

A. Click the Gradle icon on the right to expand the project list as shown below:

B. After the completion of the second step, the corresponding AAR file will be generated in the app — Build — Outputs — AAR directory of the project, as shown in the figure below

C. If the aar package needs to be signed, we will configure the signature in the build.gradle directory of App:

To set a signature, perform the following steps:

D. Add signingConfigs to app/build.gradle, as shown below:

After e.igningConfig is done, the Release configuration must be specified in buildTypes, as shown below:

What is the difference between a JAR and an AAR? 1. Address of file generated after packaging:

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

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

Jar contains only classes files, not resource files. The AAR contains not only classes files but also resource files and can be published to the Maven library, where users can get the latest AAR files directly by changing the version number

5. The aar package process of a sub-module in the project is as follows: The AAR file can be generated after the following operations

Vi. The above is the process of packaging the complete project or the sub-modules in the project into AAR. After actual practice, friends no longer need to worry about not being able to package the SDK.

In the build.gradle directory of your App, do the following configuration to import the AAR package:

7, the imported name and libs directory should be the same, rebuild the project, will find error, error message is as follows:

The imported project cannot be found. Do the following configuration to solve the problem:

Repositories {// Libs directory flatDir {dirs "libs"}}Copy the code

Viii. Rebuild the project and it is running successfully as expected:

Finally, put a running effect:

Friends if you are interested can go to try, just put two aar package here, you can use your library or small example, project, etc., can encapsulate their independence after the SDK for external use, the next post will arrange how to incorporate the aar of third-party aar and the whole project into an aar, which meet more pit.