JitPack – Forget about cloning public repositories on Android

As Android developer, you will need to add dependencies to your project sooner or later.  Those dependencies are generally published in package repositories such as Maven-Central or JCenter, but how can we get Android or JVM open source libraries not published in any package repository existing in a public Git repository? Should I clone the code and include as part of my project? No! With JitPack, you can build Git projects on demand and it provides you ready-to-use artifacts (jar or aar). The only requirement is that, if library has not been published in JitPack, then it must have at least one release in its Git repository (GitHub, BitBucket, GiLab…).

In one of my latest projects, one of the requirements was to connect with an ownCloud instance so users could access to their remote folders and files. OwnClouders have done a great job with the Android library, but it is not published in any of those package repositories at this moment. I hope, in the future, they upload the library to a Central repository but, due to I was opposed to download the code and include it in my project, I started to research an alternative option and I discovered JitPack, that helped me to simplify my job.

JitPack - coding

How can we use JitPack?

It is incredibly easy to include a dependency with this tool and it can be summarized in just 2 steps:

First, add the JitPack maven repository to the list of repositories in your root gradle file.

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

Second and finally, add dependency information in your app or library gradle file.

compile "${GROUP}:${ARTIFACT}:${VERSION}"

where

  • GROUP is domain of Git hosts plus repo username.
    • GitHub: com.github.<Username>
    • GitLab: com.gitlab.<Username>
    • BitBucket: org.bitbucket.<Username>
  • ARTIFACT consists in repository name.
  • VERSION is release name, commit hash or branch name followed by -SNAPSHOT.

Examples

Due to I have been working with the ownCloud library, I am going to describe some examples explaining how we can use JitPack to add it with:

1.  a specific release, e.g. the release oc-android-library-0.9.15:

compile 'com.github.owncloud:android-library:oc-android-library-0.9.15'

2. a precise commit identified by its hash, for example, b2034e1be22e429e53defadcd22ca6259fd7af50:

compile 'com.github.owncloud:android-library:b2034e1be22e429e53defadcd22ca6259fd7af50'

3. a particular branch, for instance, develop:

compile 'com.github.owncloud:android-library:develop-SNAPSHOT'

Therefore, it is very straightforward to add a dependency with this tool in our Android projects.

Troubleshooting

I set the version number but it fails…

Remember that you have to include the version name, not the version number. For example, imagine we want to add glide library. With Maven Central, it would be

compile 'com.github.bumptech.glide:glide:3.7.0'

and with JitPack:

compile 'com.github.bumptech:glide:v3.7.0'

“V3.7.0” is the name of the release, not “3.7.0”, as you can see on GitHub releases folder.

The version name is ok, but it still fails…

Check out JitPack main page. You can look up repositories in the main page, it guides you to include the dependency in your project.

I followed all previous steps but it still fails…

Unfortunately, JitPack does not guarantee the code is built. Read JitPack documentation, paying also attention to FAQ section and unforeseen obstacles that Nish Tahir comments in his post.

Related articles

https://ahorasomos.izertis.com/solidgear/android-priority-job-queue-background-tasks

https://ahorasomos.izertis.com/solidgear/ocr-on-android

https://ahorasomos.izertis.com/solidgear/pdf-reports-android

Leave a Comment

¿Necesitas una estimación?

Calcula ahora