Image by Free-Photos from Pixabay

Importing Android libraries from the GitHub Package Registry

Prasad Pulikal
Nov 7 · 3 min read

Click here to view the full article on publishing and using an Android library from the GitHub Package Registry


GitHub has recently introduced the GitHub Package Registry, a package management service where developers and organisations can publish packages either publicly for the open source community or privately for use within an organisation.

Until recently the service was available as a limited public beta. Currently it is available free for public repositories and with a pay-as-you-go pricing model for private repositories. More information can be found at the below link:


Using an Android library from GitHub Package Registry within an Android Application

Currently the GitHub Package Registry requires us to Authenticate to download an Android Library (Public or Private) hosted on the GitHub Package Registry. This might change for future releases.

Steps 1 and 2 can be skipped if already done while publishing a library

Step 1 : Generate a Personal Access Token for GitHub

Step 2: Store your GitHub — Personal Access Token details

Alternatively you can also add the GPR_USER and GPR_API_KEY values to your environment variables on you local machine or build server to avoid creating a github properties file

Step 3 : Update build.gradle inside the application module

def githubProperties = new Properties() githubProperties.load(new FileInputStream(rootProject.file(“github.properties”)))repositories {
maven {
name = "GitHubPackages"
/* Configure path to the library hosted on GitHub Packages Registry
* Replace UserID with package owner userID and REPOSITORY with the repository name
* e.g. "
https://maven.pkg.github.com/enefce/AndroidLibraryForGitHubPackagesDemo"*/
url = uri("https://maven.pkg.github.com/UserID/REPOSITORY")
credentials {
username = githubProperties['gpr.usr'] ?: System.getenv("GPR_USER")
password = githubProperties['gpr.key'] ?: System.getenv("GPR_API_KEY")
}
}
}
dependencies {
//consume library
implementation ‘com.example:package’ // Replace with the package id
....
}

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade