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:
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).
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.
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.
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)
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()
}
}