How to check what is the latest version of a dependency to use in gradle
Asked Answered
A

8

32

I've always added dependencies like this:

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

but in the recent versions of Android Studio, they recommend not to use the + as it can lead to errors. How to know what's the latest version? I can try every combination of 19.y.x until gradle complains, but what's the real way do check?

edit: sometimes, that page helps me figure it out.

Aubervilliers answered 25/9, 2014 at 0:23 Comment(0)
S
40

There may be other ways, but here is what i use:

You can find out the latest version using Android Studio by replacing the version number of your library in build.gradle compile line, with just + , and click on Sync Now in upper right corner of the window.

in your case, for example

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

Android Studio will pop up a hint/bulb, which has options Replace with specific version you can click, which will fill-in the latest version in-place of +. Please see below screeshot:

android studio hint

If this doesn't work the first time, let gradle complete its sync, and retry (replace + with + or any file modification will do, click the sync now again and hint bulb will show up).

For example, for your library, i simply pasted this line compile 'com.android.support:mediarouter-v7:+' under my dependencies and followed the above process, Android Studio filled in with below version

.

Stefanstefanac answered 25/9, 2014 at 1:0 Comment(4)
It auto completed with v7:19.1.0, but if I enter v7:19.9.0 manually, it also works (compile & run).Aubervilliers
it gives me error if i use 19.9.0, works ok with 19.1.0. please see this. I clicked on install repository link, but continues to give error. Goes away if i use 19.1.0.Stefanstefanac
That's weird... What version of AS are you using? I'm on 0.8.9. I can actually put any 19.x.y, it will work. 20.0.0 also works, but 20.0.1 will give me the same error as you.Aubervilliers
i am using latest AS 0.8.11. Once i downloaded latest support library, the + trick autocompletes to 20.0.0 for me as well. The bubble hint will automatically pick the latest/correct version available, and will stop giving the warning message you mention in your question.Stefanstefanac
P
14

Relying on latest version is indeed a dangerous thing to do. Your build can break without you changing anything, just because some library broke backwards compatibility.

The easiest way to know when new version of a library is out is to subscribe to new version notifications in Bintray.

Just click on the "Watch" button on the package page and you'll get an email every time new version is out. Then you'll be able to update the dependency, test it, and only then commit the build script with the new version.

Watch package in Bintray

Pegpega answered 25/9, 2014 at 0:50 Comment(9)
It can be a valid way, but in the specif case com.android.support:mediarouter is an android support library, and the best place to search them isn't Bintray or Maven.Aldine
It comes with the SDK, so I am not sure what the problem with it? All you need is the latest SDK, and look on the jar file in libs folder. It can't "surprise" you with a new version without your knowledge. Why one need a special tool for figuring out the latest?Pegpega
From the libs / jars that come with the SDK, how to tell what version to use?Aubervilliers
Just look at the jar file name?Pegpega
sdk/extras/android/support/v7/mediarouter/libs/android-support-v7-mediarouter.jarAubervilliers
Ouch. Any metadata inside the jar? Manifest? pom.xml?Pegpega
There's META-INF/MANIFEST.MF: [Manifest-Version: 1.0 Created-By: 1.6.0_45 (Sun Microsystems Inc.)] But the rest is .classAubervilliers
Cruel. So it won't help you. What I wonder is how Gradle knows the version then? Or just it suck everything from the lib folder of the installed SDK? If that's the case, you don't need to provide any version, since it's not listed anywhere. Dunno. My answer still stands for all the 3rd parties though :)Pegpega
I think this is the coolest way. I found another nice library (a project which extended the one I was using!) which "watch"ing things I wanted to.Rob
A
5

As already mentioned by some other answers you should not use + in dependencies because it may lead to unpredictable builds, so its always better if you first test your builds once a new update is available.

With android studio 2.2 and above Project Structure will show you the latest dependencies available.

  1. Activate it by going to Android Studio > Settings > Build, Execution, Deployment > Gradle > Experimental and check the Use new Project Structure dialog
  2. Then open it by going to File >Project Structure > Image showing updates dialogMessages

Original Answer

Adamik answered 30/6, 2017 at 5:26 Comment(1)
seems to be gone on android studio 3.1 canary 5, can anyone confirm?Table
I
2

Recently, I have found this.

Go to File -> Project Structure

Select the Module, where you want to add the dependency.

Go to the Dependencies Tab

Click + and Choose Library Dependency

Choose whichever Library you need from the list.

(There is also an option for Search, never tried though.)

That's it.

Done.

Thank You.

Inkstand answered 16/11, 2017 at 13:25 Comment(1)
IMO best solution. Does not require any plugins. Works with most recent Android Studio Flamingo & libs.versions.tomlJointworm
D
1

I use these two links.

This link gives me the latest buildTools Version
https://developer.android.com/studio/releases/build-tools.html



This link gives me the latest supportLibraryVersion https://developer.android.com/topic/libraries/support-library/revisions.html

Detergency answered 4/10, 2017 at 8:17 Comment(0)
A
0

Avoid to use + in version declare.

You can try andle to check if dependency out of date, also the build tool version and sdk version.

Simple three step:

1. install:

    $ sudo pip install andle

2. set sdk:

    $ andle setsdk -p <sdk_path>

3. update depedency:

    $ andle update -p <project_path> [--dryrun] [--remote]

--dryrun: only print result in console

--remote: check version in jcenter and mavenCentral

Alert answered 11/10, 2015 at 1:47 Comment(0)
B
0

the answer of ashoke is correct if you want the latest version.

But if you just want to replace "+" by the version you are currently using (therefor protection yourself against bug in future update)

eg:

 compile 'com.android.support:appcompat-v7:21.0.+'

to

 compile 'com.android.support:appcompat-v7:21.0.3'

(but not using 23.0.1)

this is the easiest way, no software needed:

run

$ ./gradlew clean tasks --debug > ~/whatever.txt

then look for "com.android.support:appcompat-v7:21.0."

a few line below you will see

"Using com.android.support:appcompat-v7:21.0.3 from Maven repository"

Buskus answered 28/4, 2016 at 9:54 Comment(0)
G
0

If it is a dependency that comes from Google's maven repository, the best way these days is to go to https://maven.google.com , where google now lets you browse all their libraries and see all the versions available, including the latest version. It looks like this:

enter image description here

You can even do a search for a specific library, and then expand/collapse it as desired:

enter image description here

Gilda answered 8/5, 2020 at 14:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.