How to publish Android library to Github package as a Maven repository

HoangVu
2 min readOct 10, 2020

--

In the github world, everyone must have known jitpack or jcenter or like a repository that help us easy to use public library.
Recently, adapt to the new project in my company I have to use private library that must be published on Github package as well base on company security policy.

So, Today I would like to introduce Maven-Publish-Plugin that can help us solve this problem.

First of all , What’s Github packges?
Github has released Github Packages last year. You can now easily host your private libraries without subscribing to another service such as jitpack or jcenter or google etc…
Github Package is a package management service that makes it easy to publish packages with source code . You can easily distribute the Android Library as an AAR.

  1. Step 1
    Generate Personal Access Tokens ( How to generate? )
Scopes for the token

2. Step 2

Create a new Android project and make it as Android Library project.
(Create an Android Library)
Make a new github.properties file in Android root project and add the github user name and token.

username=USERNAME
token=GITHUB_PERSONAL_ACCESS_TOKEN

We recommend you add github.properties file to the .gitignore to keep personal github information private.

3. Step 3

The maven repository for GitHub Packages has the following pattern:

https://maven.pkg.github.com/{repository owner}/{repository}

So, update the build.gradle in library module as below
library:build.gradle

4. Step 4
Now you can build AAR and publish it to the Github package by command.

Run below command to build and generate the library

./gradlew clean assembleRelease

Make sure myLib-release.aar has generated at build/outputs/aar/

AAR file

5. Step 5

Finally, just run below command to publish aar file to github package

./gradlew publish
Packages lib

Done :)

Next post I will introduce how to use this library in real project?
It’s so easy as well. Just like that

dependencies {
implementation 'com.vegeta:my-lib:0.1'
}

Happy coding!

--

--

HoangVu
HoangVu

No responses yet