How to publish your own SDK or library in Android Studio (Part: 1)

Implementation of jitpack for publishing SDK or library

Govind Prajapati
4 min readAug 4, 2020
Source

During the development, there is some code or module which are used commonly in many projects. For example in Android Application Development developer needs to use some package for API call (which establish the connection between client and server for accessing the data from database). So that time either developer import the all files from that module to the current project or developer can just add a single line to the build.gradle file. So the first way to import all files from module to our project is too lengthy as compare to include just one line in build.gradle file.

Hence we are preferring to use SDK or library in our project which is so helpful to developers. Many of us must have seen a lot of libraries especially in Github or Bitbucket that look like this:

depedencies.gradle

If you have something like this in the build.gradle of the module then you are ready to go. The library is now usable. So there, we will learn how to publish our own SDK or library.

How does Gradle pull a library from Repository?

Before we start talking about how to upload a library to jcenter. We should start with how Gradle fetch a library from the repository. For example, when we type like below in build.gradle, how are those library files magically downloaded to your project.

It is a combination of GROUP_ID:ARTIFACT_ID: VERSION

So Gradle is able to identify a library by the above combination. In my case it will be:

GROUP_ID = com.github.govindsa1011
ARTIFACT_ID = OwnSDK
VERSION = 1.0.0

GROUP_ID defines the name of the library’s group. It is possible that there would be more than one library with different functionality in the same context or from the same company. If the library is in the same group, it would share the same GROUP_ID. Generally, we name it with the developer’s package name and then follow with the name of the library’s group, for example, com.squareup. And then defines the name of the library in ARTIFACT_ID. For VERSION, there is nothing but a version number. Although it could be any text I suggest using Semantic Versioning if you want.

Here is the real example of the library from Square. You will notice that each one could be easily recognised the library’s and developer’s name.

square_build.gradle

How can we publish?

There we have the following option to publish our library or SDK:

  1. JitPack

I guess there are a lot of ways on how to do this and the easiest way would be to use something like Jitpack and it is pretty easy to follow like this:

Open your GitHub repository where your code is located, In my case, my GitHub repository is here.

Now create a release from your Github repository : (Click on the 0 releases tab and create a new release and publish the release).

Tag version is the version of your release. Tag Title is the title of release and Provide your release description in Describe release.

Now publish your release 😊

How can we use this release in Android Studio?

Just visit the Jitpack and enter your Github username and repository name then clicks on look up like this :

and then you are ready to go. But the thing is that you must include jitpack’s maven URL so you can access your library.

2. jCenter and Maven Central

jcenter is a Maven Repository hosted by bintray.com. You could find the whole repository here. jCenter is used by default in Android Studio, also it includes everything that Maven Central has and even more.

Maven Central is a Maven Repository hosted by sonatype.org. You could find the whole repository here.

In order to use jCenter(if not already included) and mavenCentral in Android

you have to do something like this:

root_build.gradle

Let’s move to Part 2 of this blog to understand How to upload your library to jcenter and how can we publish?

--

--

Govind Prajapati

Hi, I am a software developer at Solution Analysts. While not developing apps, I share my thoughts with peers. I just love to read, write, roam, and code!