Cover image for Develop & Publish your own SDK in Android - Part 1(Know an AAR file)

Develop & Publish your own SDK in Android - Part 1(Know an AAR file)

mohitrajput987 profile image Mohit Rajput ・3 min read

β€œAndroid is the kind of runaway smash hit that techies spend their careers dreaming about.” - Daniel Lyons

A few days ago, we launched an Android library called App Utility, which has various utility APIs which are used in almost all Android projects i.e. validations, shared preferences etc. This library is in the initial development face and launched specially to write this tutorial.

In addition to JAR files, the Android also makes use of a binary distribution format called Android ARchive (AAR). The .aar bundle is nothing but the binary distribution of an Android Library Project.

An AAR is similar to a JAR file, but it can contain both resources and compiled byte-code. An AAR file can be included in the build process of an Android app similar to a JAR file.

As we all are familiar, in Android Studio, if you wish to include any library, for example, SmilePass Face SDK, you can do it by adding following lines to build.gradle file-

dependencies {
implementation 'com.otb.utility:preference:0.0.1'

Have you ever wondered how does gradle pull library from the repository? Basically, we need to know that a gradle dependency string consists of three parts-

dependencies {

In the above example, GROUP_ID is com.otb.utility, ARTIFACT_ID is preference and VERSION is 0.0.1.

GROUP_ID- It defines the name of the library group. It is possible that multiple libraries which perform the job of the same context can belong to the same GROUP_ID. For example, the Android support library has the same GROUP_ID com.android.support for multiple support libraries. Here is the example-

dependencies {
    implementation 'com.android.support:design:' + supportLibVersion
    implementation 'com.android.support:appcompat-v7:' + supportLibVersion
    implementation 'com.android.support:recyclerview-v7:' + supportLibVersion
    implementation 'com.android.support:support-v4:' + supportLibVersion
    implementation 'com.android.support:exifinterface:' + supportLibVersion;

When you add a gradle dependency to the build.gradle file and sync the project, Gradle will ask maven repository if corresponding AAR and other files exist. For example, for the gradle dependency com.smilepass.mobilesdk:facesdk:1.0.0, you could find its library files from here.
Then Android Studio downloads those files to our machine and compiles the project. Now you can access functionalities of this SDK in your project.

Know an AAR File Format

AAR file is developed on top of a JAR file. It was invented because JAR file cannot contain Android specific files i.e. resources, manifest, assets, JNI etc. An AAR file contains all these things and it is a normal compressed file like JAR. It contains JAR file inside it with the classes.jar name. The structure of the AAR file is as follows-

- /AndroidManifest.xml (mandatory)
- /classes.jar (mandatory)
- /res/ (mandatory)
- /R.txt (mandatory)
- /assets/ (optional)
- /libs/*.jar (optional)
- /jni/<abi>/*.so (optional)
- /proguard.txt (optional)
- /lint.jar (optional)

Develop & Publish Your Own Android Library

When you get a chance to develop your own SDK for the first time, few questions are likely to come in your mind-
What are the best practices to structure and develop an SDK?
How to obfuscate SDK, how is it different from normal application projects?
Where and how to publish SDK to create its Gradle dependency?
How to provide tutorials and sample apps to developers for the integration guide?

So that’s all? Are these questions enough to get started?
The answer is - NO.
You might not realize, but each question is the root of other sub-questions. When you dive in the ocean of these questions, you will feel many things coming towards you. To float your boat well, we have summarized these questions in this tutorial.

To get started with the development of your own Android library, read the PART-2 of this article series.

Posted on by:

mohitrajput987 profile

Mohit Rajput


I love to write, solve puzzles, make artistic things. I love to code, develop logics and algorithms, writing poems, creating drawings, painting, cards etc. You can be open with me to discuss problems related to my hobbies.


markdown guide

Thanks for nice post.

I downloaded preference-0.0.1.aar from jcenter.bintray.com/com/otb/utilit...
and added dependency like mentioned here

settings.gradle - include ':app', ':preference-0.0.1'
build.gradle - implementation project(path: ':preference-0.0.1')

why will get linker error in this case, is it anything to do with pom.xml?


It cannot be used by adding aar file manually. The file is signed by bintray and can be used from its dependency only.