How to Create Your Own Android Library and Publish it in GitHub?
Last Updated :
04 Jun, 2024
Android libraries are tools for developers, that offers reusable code components and functionalities to streamline app development. Creating and publishing your own Android library on GitHub allows you to share your code with the wider developer community, contribute to open-source projects, and establish your expertise. In this article, we’ll walk you through the process of creating and publishing your own Android library on GitHub.
Steps to Create an Android Library
Step 1: Open Android Studio and Create a New Project
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Name your application as BlinkEffectExample and make sure to select Kotlin as the programming language as I’m going to use Kotlin for the source code, but you can follow the same process of creating & publishing the android library for Java as well.
Step 2: Now Create a new Module in your project
Go to file > New > New Module. Select Android Library from the options and click on Next.

Select a module type
Name Your Library as BlinkLibrary and click Finish.

Create a new module
Your module BlinkLibrary gets created.

BlinkLibrary is added to the structure
Step 3: Now, it’s time to add code to our library. For this go to your module BlinkLibrary > Java > your package name(like com.learn.blinklibrary) Right-click go to New > Kotlin/class file.

Create a new file in your module and name it as BlinkEffect make sure to choose Object from the below options.

create a new file
Step 4: Modify BlinkEffect.kt as follows
Kotlin
import android.animation.ArgbEvaluator
import android.animation.ObjectAnimator
import android.graphics.Color
import android.view.View
import android.view.animation.Animation
object BlinkEffect {
fun blink(view: View) {
// adding the color to be shown
val animator: ObjectAnimator = ObjectAnimator.ofInt(
view, "backgroundColor", Color.YELLOW,
Color.RED, Color.GREEN
)
// duration of one color
animator.duration = 500;
animator.setEvaluator(ArgbEvaluator())
// color will be shown in reverse manner
animator.repeatCount = Animation.REVERSE
// Repeat up to infinite time
animator.repeatCount = Animation.INFINITE
animator.start()
}
}
We are taking view as a parameter to the blink() function so that the blink effect can be added to that particular view. Now our library is completed. It’s time to publish it, so for this create a new repository on your GitHub and push the project to it (if not please create your Github). We will use JitPack to publish our library as it makes the process a lot easier in order to publish a library.
Publishing the Android Library in GitHub
Step 1: Create a new GitHub repository.

create a repository – BlinkEffect-library
Copy the repository’s https address.

copy the repo’s address
Step 2: Push your code
Make sure git is installed in your system. If Git and GitHub are already set up in the android studio then follow the following steps to push your code.
- Go to VCS (option from menu ) > select Enable version control enable
- A dialogue box opens, select Git and click the OK button.

You will observe that color of all filename changes to a red color as shown in the below image.

Now, change the file tree structure (left panel) from android to project as shown below.

Right-click the above project name BlinkEffectExample then go to Git > Add. You will observe the color of all filename changes to green color. Now open the terminal of your android studio (find the terminal at bottom of the android studio). Do the following to add, commit and push the code.
-> git add .
-> git commit -m "blink library added"

-> git remote add origin " Paste Your-Repository-Address"
-> git push origin master
-> Give your GitHub id name & password

Your project got pushed to the repository!

You can also follow another method to push your code (when git and GitHub is not set in the android studio). Open the system’s terminal and make sure that your current directory is in “BlinkEffectExample”(folder name of your project) and perform the following commands :
-> git init
-> git add
-> git commit -m "blink library added"
Now add your remote origin by performing
-> git remote add origin “Paste Your-Repository-Address”
-> git remote -v
-> git push origin master
Your application code got pushed to the repository.
Step 3: In your repository, go to tag and select release

click on the tag and choose release
Click on create a new release.

Now add the release version and a brief introduction about your library.

publish release
Click on publish release. Open a new tab and go to jitpack.io. Insert your repository address (in my case it’s Anju1415/BlinkEffect-library) and click on LOOKUP. Your releases will be listed.

Now click on Get it.


Your Android Library is now published and is ready to use.
Using the Android Library in Your Android App
Step 1: Now you can use this android library in any of your projects. Open any project or create a new one (Here I’m creating a new project to use this library). In your project’s build.gradle (project : applicationName) add the following line
allprojects{
…
maven { url ‘https://jitpack.io’ }
…
}

and in your app’s build.gradle (module : applicationName.app) add the dependency.
dependencies {
….
implementation ‘com.github.Anju1415:BlinkEffect-library:0.1.0’
…
}

And now you can use the library in your activity.
Step 2: Working with the activity_main.xml file
Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for the activity_main.xml file.
XML
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:id="@+id/buttonView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="GeeksForGeeks"
android:textAllCaps="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Step 3: Working with the MainActivity.kt file
Go to the MainActivity.kt file and refer to the following code. Below is the code for the MainActivity.kt file. Comments are added inside the code to understand the code in more detail.
Kotlin
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import com.learn.blinklibrary.BlinkEffect
class MainActivity : AppCompatActivity() {
private lateinit var btn : Button
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
btn = findViewById(R.id.buttonView)
btn.setOnClickListener {
// use of blink-library
BlinkEffect.blink(btn)
}
}
}
Output:
Source Code on GitHub: https://github.com/Anju1415/BlinkEffect-library
Similar Reads
How to Create a Pull Request on GitHub using Android Studio?
Creating a pull request is an important part of collaborating on projects hosted on GitHub. It allows you to propose changes to a repository, enabling others to review, discuss, and merge your changes. Hereâs a step-by-step guide on how to create a pull request on GitHub using Android Studio. Steps
2 min read
How to Create a New Branch on GitHub using Android Studio?
Creating a new branch on GitHub using Android Studio can help your development workflow by allowing you to work on new features or fixes without affecting the main codebase. In this article, we will walk you through the steps to create a new branch directly from Android Studio and push it to your Gi
2 min read
How to Add External Library in Android Studio?
Android Studio is the official IDE (Integrated Development Environment) for Android app development and it is based on JetBrainsâ IntelliJ IDEA software. Android Studio provides many excellent features that enhance productivity when building Android apps. In this article, we will learn how to add ex
2 min read
How to Create a New Branch in Git and Push the Code?
Branching in Git is a helpful feature for software developers working on a big team project. It allows the team members to work on different aspects of the software by creating a branch from the main branch. The main branch is not affected by the changes in the created branch until it is merged into
8 min read
How to Create a Tag in a GitHub Repository?
Tags are one of the important parts of Git and GitHub. We can see in the case of open source projects that the release of a particular version is attached with a tag. Tags are used to memorize a specific moment in history. Even after making multiple changes to the code, we can get back to the partic
3 min read
How to Create a Shayari Android App Using Firebase in Kotlin?
A Shayari app built in Android Studio consists of various Shayaries and categories of it using Firebase for database purposes, also you can add as many Shayaries and categories of it, indirectly to the firebases the user can access and also have share functionality on WhatsApp as well. A sample vide
8 min read
How to Create a Custom Intro Slider of an Android App?
Intro Slider in many apps is mostly used to educate the users about the app, the features of the app, and the services that our app will provide to us. In this article, we will take a look at the implementation of Custom Intro Slider in our app. What we are going to build in this Article? We will b
9 min read
How to Use Fast Android Networking Library in Android with Example?
In Android, we know multiple networking libraries like Retrofit, Volley. We use these libraries specifically for making networking requests like performing actions on API. But Besides that, there is another library called Fast Networking Library which has a few advantages over other libraries. In th
4 min read
How to Create a New Branch on Github using Pycharm?
Git is an open-source version control system. It means that whenever a developer develops some project (like an app or website) or something, he/she can constantly update, Git is a version control system that lets you manage and keep track of your source code history. Letâs say you have a project, a
2 min read
How to Create a New Fragment in Android Studio?
Android Studio is the official integrated development environment for Google's Android operating system, built on JetBrains' IntelliJ IDEA software and designed specifically for Android development. You can Develop Android App using this. Here, We are going to learn how to create a new Fragment in A
2 min read