Publishing Java / android / kotlin libraries on Jitpack

Lux Man
4 min readJun 6, 2017

--

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

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).

Select Android Library
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.

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

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.

Click on the text “ 0 releases”
focused view at release s
Press the create new release button
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.

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)

For gradle project (which we will use)
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 :

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.

--

--