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

One thought on “Use the latest version of any library with Android Studio & Gradle

Leave a Reply

Your email address will not be published. Required fields are marked *