android libraries for developers — Develop and Publish Your Own Android Library | Blog

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-

Develop & Publish Your Own SDK

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?

Publish SDK

There are plenty of platforms for hosting your Android library and create its gradle or maven dependency. You can choose over JitPack or JCenter or Maven Central.

Why JCenter?

You must have seen these lines in root level build.gradle file in an Android Project-

Create an Account on JFrog Bintray

Since jCenter is hosted on JFrog Bintray, create a new account on it by clicking on .

Create a New Repository

Add a New Package

Create a New Version

Get API Key

API Key is used for the authentication to upload your AAR file to the Bintray. Go to the Bintray dashboard and click on your name at top-right corner. You will see the following drop-down with profile related options-

Configure Bintray in the Module

After the setup of Bintray package and version, you need to configure your library in Android Studio.

Compile the Library Module

After all configuration and credentials setup, it’s time to generate the AAR and other files. Open a terminal, go to your project’s root directory and run following command-

Uploading Library to Bintray

After a successful build, it’s time to upload your library to Bintray. We can do it by running following command in the same terminal-

Add Library to jCenter

If you add a gradle dependency that you just created in any other project, you will get an error like “failed to resolve com.yourlibraryname…”. It’s because your package is added to Bintray repo only, not in jCenter yet.

Tutorials & Samples

You are ready with gradle dependency and you have tested it. It’s time to show your work to the world. How will you inform developers all around the world about your beautiful Android library?

Conclusion

After performing all these steps, you will be able to successfully distribute your Android library to the developers. Although it looks a very lengthy and complicated process, the steps are quite straightforward. For example, most of the steps of setup and configurations related to publishing the SDK are one time. It will require little effort from the next time.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
SYSTANGO

SYSTANGO

London’s leading digital agency Systango offers full service from strategy, scoping to launch & maintenance, innovative campaigns to enterprise infrastructure.