Publishing Java / android / kotlin libraries on Jitpack

Lux Man
Lux Man
Jun 6, 2017 · 4 min read
Image for post
Image for post

What is Jitpack?

For those people who don’t really know what JitPack.io is, It is Easy to use package repository for #JVM (Java, Kotlin, Scala, Groovy etc.) and #Android. It can convert your git projects into libraries which you can use in your project like this inside your app as a maven repository:

dependencies{
..........
compile 'com.github.erluxman:jitpackandroidutil:1.0.0'
..........
}

So after this brief introduction, I will explain in steps, how we can actually make and release our libraries/modules on JitPack.io. As an example I will write and host a library which can be used as normal android utility class using kotlin. Java and Kotlin Libraries are no different, at least in the eye of JitPack.io.

1. Create New Android Project:

Create A new Android Project
Image for post
Image for post

2. Create A new module(File > New > New Module) util (Your code won’t break even if you don’t but it’s highly recommended so I will follow this approach).

Image for post
Image for post
Select Android Library
Image for post
Image for post
Confirm the package name, this will be used to import the library to your project.

3. Now inside the android “util” package, Write the necessary classes and methods you are going to use as Library.

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

4. Create A project in GitHub and set it up with your project.

Image for post
Image for post

5. Then add add the remote project as origin to your local project.

git remote add origin https://github.com/erluxman/jitpack-android-util-demo.git

6. Pull the origin master and then commit it to origin/master

git pull origin master
//resolve conflicts if any
git add --all
git commit -m "initial commit"
git push origin master

7. Create Release from the GitHub repository and publish it.

Image for post
Image for post
Click on the text “ 0 releases”
Image for post
Image for post
focused view at release s
Image for post
Image for post
Press the create new release button
Image for post
Image for post
Give your release name and title

8. Go to Jitpack.io , paste the URL of your GitHub Project into the lookup input field and press the “look up” Button, Wait for a while the gradle build runs in remote servers of JitPack.io.

Image for post
Image for post
See the Log and status

If the build was successful, the file icon turns green else it turns red. If the file turns red not only the gradle build failed, but also you won’t be able to access the github repo as library.

9. If you get the green file icon(successful build) then scroll down you will see how to use your library.(If your build fails -> “red file icon”, Repeat all the previous process and make the project pass the build)

Image for post
Image for post
For gradle project (which we will use)
Image for post
Image for post
For other maven projects

10. Like shown in the above images, add :

compile 'com.github.erluxman:jitpack-android-util-demo:v1.0.0'

inside dependency of your app build.gradle file.

allprojects {
repositories {
jcenter()
maven { url 'https://jitpack.io' }
mavenCentral()
}
}

inside project build.gradle file ( root gradle file).

And then sync the project with gradle files.

11. Finally you will be able to use your library into your project like this :

Image for post
Image for post
See you can even see the available methods as hints.

You can find the repository I used for demo here

https://github.com/erluxman/jitpack-android-util-demo

Thank you so much for following the post. Hope this will help you.

Image for post
Image for post

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