How To Do Publish Android Library In Jitpack.io

Emre Kaydu
4 min readJul 2, 2023

Android libraries provide reusable code blocks, functions, and components that help other developers speed up their software development processes and make their applications more robust and functional. However, creating an Android library and sharing it with users can come with its own set of challenges. The publishing process requires careful planning and attention to detail. Fortunately, there are many popular publishing platforms and tools in the Android community that make it easier to share your library with developers worldwide.

In this blog post, we will walk you through the step-by-step process of how to publish Android libraries in the simplest way possible. We will learn about the necessary preparations and considerations before diving into the publishing process. We will also explore how to configure Gradle settings to ensure a smooth publishing experience.

If you’re ready to embark on the journey of publishing your Android libraries to the world, this blog post will guide you through the process in the simplest way, ensuring a successful publishing experience. So, let’s get started!

You can see this link GitHub resource.

If you want to detail explanation. You should read Android Documentation.

Step 1

  1. Create android project. Empty Activity. (I use compose empty activity).
  2. Give name “SampleAndroidLibrary”
Figure 1

When ı click the Finish button. Android Studio create default MainActivity Class that has a named Greeting composable function.

We will create “Greeting” Library.

Step 2

  1. Create module in Android Studio. This module independent main project.
  2. Select File > New > New Module
Figure 2

When ı click new module open configuration frame. There are many options what you want to do. In This article, we are focus on Android Library.

3. Give a name to library as “greeting”

Figure 3

Android Studio create independent module. In this module, there is gredle file for greeting library.

Figure 4

Step 3

we move Composable Greeting function to Greeting Library. However, Greeting lib has not composable library. When we move composable function, Android Studio give much more error. We need configure library module for compose features.

We remove all dependencies because of unnecessary dependencies. I add dependencies related to compose to build.gradle(:greeting).

Figure 5
Figure 6
Figure 7

Because of the Greeting library independent root app. In MainActivity, composable Greeting function not found. To check every think is ok, we add library to root app.

we add library to root project in (build.gradle(Module:app)) dependencies

implementation project(":greeting")
Figure 8

In see Figure 10, we can add library root project successfully. Now, we publish library in jitpack.io

Step 4

  1. Add ‘maven-publish to gradle:Greeting
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
id 'maven-publish'
}

2. Create yml file in project (not app folder)

3. Give name to jitpack.yml

Figure 9 (create jitpack.yml file in Project)

4. Add to code below to jitpack.yml file (I use java 17, Define whichever version of Java you are using such as openjdk8, openjdk11)

jdk:
- openjdk17

5. Finally, add code below to “gradle:Greeting” in end of dependency

afterEvaluate{
publishing{
publications{
release(MavenPublication){
from components.release

groupId='com.github.kayduemre'
artifactId = 'greeting'
version = '1.0'
}
}
}
}

groupId is start with ‘com.github’ after that adding github account name.

artifactId must be same with library name.

Step 5

I assume that you know push project to GitHub.

  1. Click to “Create a new release” in Figure 10
Figure 10

2. In opening screen, give a tag as version number 1.0. It will use in jitpack.

3. Click to publish release.

Figure 11

Step 6

In final step, we publish to library.

  1. Open jitpack.io in browser.
  2. Click to “Get It button” in opening screen. if Log status color green, publishing success. but if status color red, publishing failed.
Figure 12

Step 7

To get a Git project into your build:

  1. Add the JitPack repository to your build file

Add it in your root build.gradle at the end of repositories:

allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}

2. Add the dependency

dependencies {
implementation 'com.github.kayduemre:SampleAndroidLibrary:1.0'
}

Now other developers can get library.

--

--