How to Update a Library Version in Android build.gradle

DevOpsDevOps Tools

YOUR COSMETIC CARE STARTS HERE

Find the Best Cosmetic Hospitals

Trusted • Curated • Easy

Looking for the right place for a cosmetic procedure? Explore top cosmetic hospitals in one place and choose with confidence.

“Small steps lead to big changes — today is a perfect day to begin.”

Explore Cosmetic Hospitals Compare hospitals, services & options quickly.

✓ Shortlist providers • ✓ Review options • ✓ Take the next step with confidence

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 publishToMavenLocal in the library project. Your updated artifact will be available in your local ~/.m2 repository.
  • 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 .aar or .jar file 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

  1. Make your code changes in the forked library project.
  2. Increment the version (and optionally versionCode / versionName) in the library’s build.gradle.
  3. Build and publish the library (local Maven, JitPack, or file dependency).
  4. Update the version string in your app’s build.gradle dependencies block.
  5. Sync Gradle and verify the build succeeds.

Original question sourced from stackoverflow.com.

0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
0
Would love your thoughts, please comment.x