How to create your own Android Library and publish it

Anuj Gupta
Dec 29, 2017 · 4 min read
Image for post
Image for post

In this tutorial we are going to create our own Android Library and publish it. By publishing the library you can use the library in any of your future projects. Plus others can use the library in their projects.

So let’s get started shall we

Creating The Android Library

The ToasterExample will be our sample application to show an example use of our application.

Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post

Click on Finish and your project will be ready.

Now create a new Module in your project

Image for post
Image for post

Select Android Library from the options and click on Next

Image for post
Image for post

Name Your Library as ToasterLibrary and click finish.

Image for post
Image for post

Your module toasterlibrary has been added.

Image for post
Image for post

Now we need to add code in our library. Create a new Class in your module and name that class ToasterMessage

Image for post
Image for post
Image for post
Image for post

Modify ToasterMessage.java as follows

We are taking context and message as parameter and displaying a Toast Message.

So our Library is completed and now its time to publish the library. To publish the library we are going to use JitPack because it makes the process of publishing a library a lot easier. All you need is a github repository.

Publishing the Android Library

Image for post
Image for post
Image for post
Image for post

Copy the repository’s https address. Now open terminal and make sure that your current directory is Toaster (Your Project’s Directory) and perform the following commands

Image for post
Image for post

Now add your remote origin by performing

git remote add origin “Your-Repository-Address”

Image for post
Image for post
Image for post
Image for post

And finally push the code.

Image for post
Image for post

Now in your github repository click on releases

Image for post
Image for post

And create a new Release

Image for post
Image for post

Publish the release. Open a new tab and go to jitpack.io.

Insert your repository address and click on Lookup. Your releases will be listed . Now click on Get it.

Image for post
Image for post
Image for post
Image for post

Congratulations your Android Library has been published and is ready to be used.

Using the Android Library

In your project’s build.gradle add the following line

maven { url ‘https://jitpack.io’ }

Image for post
Image for post

and in your app’s build.gradle add the dependency

compile 'com.github.aj019:Toaster-Library:0.1.0'
Image for post
Image for post

And now you can use the library in your activity

Image for post
Image for post

And voila we get the following output

Image for post
Image for post

If there is any question or confusion regarding the tutorial . Feel free to ask your questions in the comments below.

Source Code is available on github at

Thanks for reading this article. Be sure to clap/recommend as much as you can and also share with your friends. It means a lot to me.

Also, Let’s become friends on Twitter, Linkedin and Github.

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

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