Codementor Events

Create your first android library

Published Oct 23, 2019
Create your first android library

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.
Start writing here...

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.

0*3CyqIRxCo94PAKRl.jpg
After successful build please ensure library is added to your existing project dependencies.

api project(:'yourlibraryname')

0*Fhbmf_QN3p0sXuOn.jpg

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
0*zl6Kz9vmHmDI2KKj.jpg

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.

0*SG51E4HbLuUQ9_c5.jpg

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.
0*EW6HOpkQW2M5pzS0.jpg

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'
    }

full source code

Discover and read more posts from Ajith v
get started
post commentsBe the first to share your opinion
Show more replies