When you fork an Android library from GitHub, make changes, and want to consume that updated library in another project, you need to understand how Gradle versioning works. This guide walks through the process of incrementing a library version and updating the corresponding dependency declaration in your app’s build.gradle file.
The Problem
A common scenario: you’ve forked an Android library project on GitHub, cloned it locally (for example via SourceTree), made your own changes, and now want to reference your updated version from another app using Gradle. You need to bump the version so Gradle can distinguish your build from the original.
For example, you might want to move from:
implementation 'com.github.lib:library-name:0.3.1'Code language: JavaScript (javascript)
…to your newly versioned build:
implementation 'com.github.lib:library-name:0.3.2'Code language: JavaScript (javascript)
Step 1: Update the Version in the Library’s build.gradle
Open the library module’s build.gradle file (not the app module — the library module itself). Look for the version declaration. Depending on how the library is set up, you will find something like one of the following patterns:
// In the library's build.gradle
group = 'com.github.lib'
version = '0.3.1'
// Or inside android {} block:
defaultConfig {
versionName "0.3.1"
versionCode 1
}Code language: JavaScript (javascript)
Increment the version to reflect your changes. Following semantic versioning, a patch-level fix increments the third number:
group = 'com.github.lib'
version = '0.3.2'Code language: JavaScript (javascript)
Step 2: Publish or Reference Your Updated Library
After incrementing the version, you have several options to make the library available to your other project:
- Publish to a local Maven repository — Run
./gradlew publishToMavenLocalin the library project. Your updated artifact will be available in your local~/.m2repository. - Publish to JitPack — If your fork is pushed to GitHub, JitPack can serve it as a dependency directly from your repository. Tag a release and reference it using the JitPack coordinates.
- Use a local file dependency — Reference the generated
.aaror.jarfile directly as a local module dependency without publishing to any repository.
Step 3: Update the Dependency in Your App’s build.gradle
Open your consuming app’s build.gradle (Module: app) and find the dependencies block. Update the version string to match the new version you declared in the library:
dependencies {
// Old version
// implementation 'com.github.lib:library-name:0.3.1'
// Updated to your new version
implementation 'com.github.lib:library-name:0.3.2'
}Code language: JavaScript (javascript)
After editing the file, click Sync Now in Android Studio (or run ./gradlew build from the command line) to pull in the updated dependency.
Note on the compile Directive
The original question used compile, which was the standard dependency configuration in older versions of the Android Gradle plugin. Since Android Gradle Plugin 3.0, compile has been deprecated and replaced with implementation (or api for transitive exposure). Use implementation in modern projects:
// Deprecated (AGP < 3.0)
compile 'com.github.lib:library-name:0.3.2'
// Correct for AGP 3.0+
implementation 'com.github.lib:library-name:0.3.2'Code language: JavaScript (javascript)
Quick Reference: Version Bump Checklist
- Make your code changes in the forked library project.
- Increment the
version(and optionallyversionCode/versionName) in the library’sbuild.gradle. - Build and publish the library (local Maven, JitPack, or file dependency).
- Update the version string in your app’s
build.gradledependencies block. - Sync Gradle and verify the build succeeds.
Original question sourced from stackoverflow.com.