Use the latest version of any library with Android Studio & Gradle

Isn’t it annoying whenever you want to add a new dependency to your project you have to know the exact version to add, not any more! This ‘hack’ makes use of the Gradle + syntax that allows you to not specify a version of the application. However using + syntax in your code is dangerous as this will always use the latest version of the dependency in question, doing this can lead to unstable builds over time (you write the code against version 1.0 then a week later 2.0 comes out your build will automatically update, potential bugs, bugs everywhere!

Step 1

Add the dependency you want:

dependencies {
    compile 'com.android.support:appcompat-v7:XXX'
}

But we don’t know what the latest version is! Use the + syntax:

Step 2

dependencies {
    compile 'com.android.support:appcompat-v7:+'
}

You’ll now get a lint warning saying + versioning is dangerous (as we outlined above).

Step 3

Press this key combo
on Mac: ALT + 1
on Windows: ALT + ENTER
for the quickfix menu and select “replace with specific version”.

Screen Shot 2015-06-21 at 12.33.58

TADA

dependencies {
    compile 'com.android.support:appcompat-v7:22.2.0'
}

TLDR? Watch this gif:

Gradle Version

2 thoughts on “Use the latest version of any library with Android Studio & Gradle

  1. Thanks, thanks, a big thanks for this really super post. It’s being 4-5 months since i am in android development and each time i add some library or i need to change in gradle, i always go to file by file to find the version of each library. But now I don’t need to waste my time finding? version. Thanks again.

Comments are closed.