Create your first android library

Ajith v Giri
Sep 1, 2018 · 2 min read

An Android library is like JAR files, the Android ARchive(AAR) bundle is the binary distribution of an Android Library Project.

Apart from JAR file, AAR contain resources as well as compiled byte-code and assets are not supported. we can make library modules which can be used as dependencies in Android projects.

1.Getting started

In Android Studio each library is a module. To create a new library module in an existing Android project.

select  File ▸ New ▸ New Module and select Android Library.
AndroidLibray
AndroidLibray

After successful build please ensure library is added to your existing project dependencies.

api project(:'yourlibraryname')
Imgur
Imgur

2.Create classes & resources for the library

I have created a library named infinityscroll which is used for pagination in RecyclerView. infinityscroll consist of two classes, both are accessible to the main app module

Imgur
Imgur

3.Share the project in GitHub.

Upload the created project to GitHub and create a release for your library.

Add version tag & title then click publish release.
Imgur
Imgur

4.Publishing the library

The final step go to jitpack.io and sign in with your GitHub account. You see the GitHub repositories on the left side choose it from there or you can type/paste the project GitHub url in the textfield.

Imgur
Imgur

Finally

Finally you’ll get the dependency of published library like this

repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.ajithvgiri:recyclerview-pagination:v1.0'
}

Ajith v Giri

Written by

Mobile app developer with an eye for design.Loves to create apps with good UI/ UX that doesn’t annoy people.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade