How to create your own Android Library and publish it

Anuj Gupta
4 min readDec 29, 2017

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

Open Android Studio and create a new Project. Name your application as ToasterExample and your project name as Toaster.

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

Click on Finish and your project will be ready.

Now create a new Module in your project

Select Android Library from the options and click on Next

Name Your Library as ToasterLibrary and click finish.

Your module toasterlibrary has been added.

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

Modify 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

So now we are going to create a new github repository and push our code

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

Now add your remote origin by performing

git remote add origin “Your-Repository-Address”

And finally push the code.

Now in your github repository click on releases

And create a new Release

Publish the release. Open a new tab and go to

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

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

Using the Android Library

Now you can use this android library in any of your projects .

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

maven { url ‘’ }

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

compile 'com.github.aj019:Toaster-Library:0.1.0'

And now you can use the library in your activity

And voila we get the following output

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

Check out other apps on the App Store :-

Check out other apps on the Play Store :-

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.

Subscribe to the Youtube Channel :-