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:
[code language=”groovy”]
dependencies {
compile ‘com.android.support:appcompat-v7:XXX’
}
[/code]
But we don’t know what the latest version is! Use the + syntax:
Step 2
[code language=”groovy”]
dependencies {
compile ‘com.android.support:appcompat-v7:+’
}
[/code]
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”.
TADA
[code language=”groovy”]
dependencies {
compile ‘com.android.support:appcompat-v7:22.2.0’
}
[/code]
TLDR? Watch this gif:


Comments
2 responses to “Use the latest version of any library with Android Studio & Gradle”
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.
1000000 gracias ^^