How to check if Gradle dependency has new version?
Asked Answered
S

11

280

In Android Studio when I use a + in the version number like:
com.android.support:recyclerview-v7:21.+
I get a "Avoid using + in version numbers" warning.

But when I use a specific version number I can't always use the latest version. I have a lot of dependencies in my project.

How do I check if a dependency has a newer version?

Is there an Android Studio plugin (or something like that) to notify me when there is a newer version of a dependency?

Edit:
Android Studio highlights the outdated Android Support Libraries and Google play services. But this is not available for other custom libraries.

Android Studio highlights

Scorpaenoid answered 23/2, 2015 at 20:59 Comment(3)
For developers who are updating the library see: How to update library for new version in Bintray?Stanfordstang
In at least Android 3.0, updates for custom libraries now show the same notification as you have in your question image for the support library.Stanfordstang
@Stanfordstang this doesn't work for some dependencies for me in android studio 3.0.1Benedictine
L
229

This is now built-in to Android Studio as a Lint check. You can enable it here:

Settings > Editor > Inspections > "Newer Library Versions Available"

The description for this inspection:

Newer Library Versions Available

This detector checks with a central repository to see if there are newer versions available for the dependencies used by this project. This is similar to the GradleDependency check, which checks for newer versions available in the Android SDK tools and libraries, but this works with any MavenCentral dependency, and connects to the library every time, which makes it more flexible but also much slower.

Because of the slowdown this can introduce I'd recommend running it manually periodically, rather than having it always on. You can do this by:

Analyze > "Run Inspection By Name"

Then search for "Newer Library Versions Available", and run it on your module.

Edit: The above should just work as of Android Studio 2.3. If you're on an old version (you should update) the following may help:

Note that it appears you must have the inspection enabled in order to run it manually - so (as of Android Studio 2.0 Beta 2) you need to find the inspection in settings, enable it, then run it by name, then disable it again (to regain previous performance).

Louvain answered 12/2, 2016 at 20:2 Comment(17)
I don't know if I'm doing something wrong but that didn't work for meScorpaenoid
I had to run it on either my app module or the whole project - running it on the build.gradle file didn't work. Make sure it's enabled in Settings before you run it, too - and I've just noticed that it missed some things (it found Dagger, RxJava as being outdated, but missed Realm, Retrofit).Louvain
Yes same for me, realm is not on MavenCentral. Is your retrofit version defined like this? Mine is, and it couldn't find it either def okhttpVersion = '2.7.2' compile "com.squareup.okhttp:okhttp:$okhttpVersion"Scorpaenoid
compile 'com.squareup.retrofit:retrofit:1.9.0' - the latest release is 2.0.0-beta4 though, so I'm wondering if it ignores beta versions.Louvain
with defined version string was unable to find. It was able to find com.squareup.okhttp:okhttp:2.7.2. Also on 2.0.0-beta4Scorpaenoid
This sounds very poorly implemented by not using Gradle's dependency management properly (no http proxying, no alt repositories, no resolution strategies). Is there a reason why they reinvented the wheel instead of building on top of Gradle's apis?Tsosie
This shows the available updates in a "Inspection" tab, but it does not highlight it as a warning in build.gradle. I am yet to find a solution that does that.Ingurgitate
This answer can be updated to remove the last paragraph about enabling inspection first. Running the inspection manually without enabling in settings first worked for me on Android 2.3.3.Egoist
Had to come back to this answer to report that it ONLY works for MavenCentral dependencies. This means repositories from Jitpack or other sources are NOT automatically updated. The correct method for getting the latest version of ALL dependencies is at this answer [#28539324 (here)Egoist
Where in the heck is Settings > Editor > Inspections > "Newer Library Versions Available". I don't see a Settings in the Mac Toolbar of AS 3.x?Puto
The answer seems obsolete now, instead of "Newer Library Versions Available" we can run "Obsolete Gradle Dependency" inspection.Finbar
It seem it does not report updates for android support repository, I intentionally downgraded it, and I didn't found the library in the report, any idea why?Tory
@amitsrivastava I tried to use your solution, and it didn't found the updates found when I ran the inspection "Newer Library Versions Available", but it did found outdated android libraries, which wasn't found by the previous inspectionTory
As @Scorpaenoid told, It doesn't work with something like this: rxJavaVersion = '2.2.2' and then rxJava:"io.reactivex.rxjava2:rxjava:$rxJavaVersion" @AdamS. Do you have any solution for that? Thanks.Jarl
@AdamS Strange case i have guys. I'm using Android Studio 3.6.3, and i have opened two projects, on one of them the dependencies versions are highlited in gradle, for the other project they are not. Note: Some of the versions are implemented using ext viriables some of them are just hardcoded string and still no difference at all For the both projects i'm using same gradle versions. I really can't find out what is the problem.Errol
I think this doesn't work anymore. I'm using Android Studio Bumblebee and I get No suspicious code found message.Scorpaenoid
I'm using Android Studio Dolphin. The Newer Library Versions Available inspection finds nothing, but Obsolete Gradle Dependency does. Also, inspections have moved to Code > Analyze Code > Run Inspection by Name...Hooknose
P
292

UPDATE (05/23/18):

The newer version of Android Studio does not show version updates in the Project Structure dialog. Instead, Adam-s answer is the correct one for Android Studio 3+

Analyze > "Run Inspection By Name"

Then search for "Newer Library Versions Available"

PREVIOUS WAY:

As of Android Studio 2.2, a new Project Structure dialog shows the list of dependencies your app is using with the available updates from local AND remote repositories as well.

  • Activate it by going to Android Studio > Settings > Build, Execution, Deployment > Gradle > Experimental and check the Use new Project Structure dialog (Thanks @jessehensold)
  • Then open it by going to File > Project Structure > Messages

enter image description here

For older version of Android Studio, see other responses below.

Pronounce answered 23/2, 2015 at 21:9 Comment(15)
About the edit; it was about android-studio, because i was looking for an Android Studio plugin. Thanks for the answer but I've already seen it.Scorpaenoid
After some more research the above solution seems to be your best bet. It is easy to install and run.Pronounce
You could also manually trigger the check by doing Analyze -> Run Inspection By Name -> Newer Library Versions Available. No need to install a plugin and it will work for all the dependencies.Mohr
@Mohr as of 2016-02-18 Newer Library Versions Available lint check does not find updates for all dependencies. E.g. compile 'me.henrytao:smooth-app-bar-layout:1.0.3' gives no warning. The solution provided in above answer finds the update for this dependency.Sandeesandeep
This is not present in Android Studio anymore (using beta 2).Applegate
I can't seem to find this in Android Studio 2.2 (Beta 3) similar to @gonzalo. Do you know if they removed it or simply moved it somewhere else in Android Studio?Noggin
I had to go into Preferences>Build, Execution, Deployment>Gradle>Experimental and check the 'Use new Project Structure dialog'Riboflavin
Have to go to "Dependencies" tab to make "apply" button enabled. Some bug?Ra
I tried this with Android Studio 2.3 but the Dependencies tab of Project Structure dialog doesn't find any dependencies of my project.Wheelock
Only works for Google libraries and doesn't work with variable-defined version i.e. "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" in Android Studio 3.0.1Fetation
The dialog dissappeared in 3.2 canary :(Selfrighteous
This is not present at new Android Studio 3.1 release :-(Deteriorate
This no longer works. Please delete or update your answer. The answer below from Adam S works.Unbelievable
@Pronounce It doesn't work if you write your libraries like this for example: implementation "com.google.dagger:dagger:${daggerVersion}"Jarl
this feature at stable channel with Android Studio 3.4Archibold
L
229

This is now built-in to Android Studio as a Lint check. You can enable it here:

Settings > Editor > Inspections > "Newer Library Versions Available"

The description for this inspection:

Newer Library Versions Available

This detector checks with a central repository to see if there are newer versions available for the dependencies used by this project. This is similar to the GradleDependency check, which checks for newer versions available in the Android SDK tools and libraries, but this works with any MavenCentral dependency, and connects to the library every time, which makes it more flexible but also much slower.

Because of the slowdown this can introduce I'd recommend running it manually periodically, rather than having it always on. You can do this by:

Analyze > "Run Inspection By Name"

Then search for "Newer Library Versions Available", and run it on your module.

Edit: The above should just work as of Android Studio 2.3. If you're on an old version (you should update) the following may help:

Note that it appears you must have the inspection enabled in order to run it manually - so (as of Android Studio 2.0 Beta 2) you need to find the inspection in settings, enable it, then run it by name, then disable it again (to regain previous performance).

Louvain answered 12/2, 2016 at 20:2 Comment(17)
I don't know if I'm doing something wrong but that didn't work for meScorpaenoid
I had to run it on either my app module or the whole project - running it on the build.gradle file didn't work. Make sure it's enabled in Settings before you run it, too - and I've just noticed that it missed some things (it found Dagger, RxJava as being outdated, but missed Realm, Retrofit).Louvain
Yes same for me, realm is not on MavenCentral. Is your retrofit version defined like this? Mine is, and it couldn't find it either def okhttpVersion = '2.7.2' compile "com.squareup.okhttp:okhttp:$okhttpVersion"Scorpaenoid
compile 'com.squareup.retrofit:retrofit:1.9.0' - the latest release is 2.0.0-beta4 though, so I'm wondering if it ignores beta versions.Louvain
with defined version string was unable to find. It was able to find com.squareup.okhttp:okhttp:2.7.2. Also on 2.0.0-beta4Scorpaenoid
This sounds very poorly implemented by not using Gradle's dependency management properly (no http proxying, no alt repositories, no resolution strategies). Is there a reason why they reinvented the wheel instead of building on top of Gradle's apis?Tsosie
This shows the available updates in a "Inspection" tab, but it does not highlight it as a warning in build.gradle. I am yet to find a solution that does that.Ingurgitate
This answer can be updated to remove the last paragraph about enabling inspection first. Running the inspection manually without enabling in settings first worked for me on Android 2.3.3.Egoist
Had to come back to this answer to report that it ONLY works for MavenCentral dependencies. This means repositories from Jitpack or other sources are NOT automatically updated. The correct method for getting the latest version of ALL dependencies is at this answer [#28539324 (here)Egoist
Where in the heck is Settings > Editor > Inspections > "Newer Library Versions Available". I don't see a Settings in the Mac Toolbar of AS 3.x?Puto
The answer seems obsolete now, instead of "Newer Library Versions Available" we can run "Obsolete Gradle Dependency" inspection.Finbar
It seem it does not report updates for android support repository, I intentionally downgraded it, and I didn't found the library in the report, any idea why?Tory
@amitsrivastava I tried to use your solution, and it didn't found the updates found when I ran the inspection "Newer Library Versions Available", but it did found outdated android libraries, which wasn't found by the previous inspectionTory
As @Scorpaenoid told, It doesn't work with something like this: rxJavaVersion = '2.2.2' and then rxJava:"io.reactivex.rxjava2:rxjava:$rxJavaVersion" @AdamS. Do you have any solution for that? Thanks.Jarl
@AdamS Strange case i have guys. I'm using Android Studio 3.6.3, and i have opened two projects, on one of them the dependencies versions are highlited in gradle, for the other project they are not. Note: Some of the versions are implemented using ext viriables some of them are just hardcoded string and still no difference at all For the both projects i'm using same gradle versions. I really can't find out what is the problem.Errol
I think this doesn't work anymore. I'm using Android Studio Bumblebee and I get No suspicious code found message.Scorpaenoid
I'm using Android Studio Dolphin. The Newer Library Versions Available inspection finds nothing, but Obsolete Gradle Dependency does. Also, inspections have moved to Code > Analyze Code > Run Inspection by Name...Hooknose
E
103

Aside from the Android Studio's built-in feature, there's nice gradle plugin called Gradle Versions Plugin that does exactly what you want, with the benefit of being plain gradle extension, which means being not bond to any IDE - just pure Gradle thing.

Gradle Versions Plugin can create reports in human readable plain text form, but can also dump it as JSON or XML which is pretty useful for automated/scripted processing.

Usage is pretty simple. Once added to your gradle file, you just do:

$ ./gradlew dependencyUpdates

and it should produce project dependency report that looks like this:

------------------------------------------------------------
: Project Dependency Updates (report to plain text file)
------------------------------------------------------------

The following dependencies are using the latest milestone version:
 - com.github.maksim88:PasswordEditText:v0.9
 - com.marcinorlowski:webnet-log:1.0.3
 - com.nulab-inc:zxcvbn:1.2.2

The following dependencies exceed the version found at the milestone revision level:
 - com.hannesdorfmann.fragmentargs:annotation [4.0.0-SNAPSHOT <- 3.0.2]
 - com.hannesdorfmann.fragmentargs:bundler-parceler [4.0.0-SNAPSHOT <- 3.0.2]
 - com.github.bumptech.glide:glide [3.7.0 <- 3.6.1]
 - com.hannesdorfmann.fragmentargs:processor [4.0.0-SNAPSHOT <- 3.0.2]

The following dependencies have later milestone versions:
 - com.github.PhilJay:MPAndroidChart [v2.2.5 -> v3.0.1]
 - com.android.support:appcompat-v7 [25.1.0 -> 25.1.1]
 - com.jakewharton:butterknife [8.4.0 -> 8.5.1]

Generated report file build/dependencyUpdates\report.txt

See docs for extensive usage examples.

Equisetum answered 31/1, 2017 at 13:36 Comment(10)
Awesome! Got here looking for this for a normal Java project. A nice general solution without Lint's Android specificity.Bokbokhara
I received error Configuration 'compile' in project ':myapp' is deprecated. Use 'implementation' instead. The CompileOptions.bootClasspath property has been deprecated and is scheduled to be removed in Gradle 5.0. Please use the CompileOptions.bootstrapClasspath property instead. when ran this.Lathing
fill the bug report here: github.com/ben-manes/gradle-versions-plugin/issuesEquisetum
The "Newer Library Versions Available" method didn't work, but this is perfect! (I use multiple gradle files with variables for lib versions)Windcheater
Can you add a picture of that plugin? I haven't found it in a list.Trainload
This is gradle plugin, not IDE's. You need to add it by hand to gradle file as documented on plugin page.Equisetum
But you need a compiling system. What if you want to find out initially which is the current version of a library.Palingenesis
Then you install "compiling system" first.Equisetum
I would vote for this as the best approach for the long term projects. Because this is a Gradle task you can add this simple as one of your build steps. This will allow you to have a semi-automatic flow of updates. Fully automated is impossible IMHO, but there are tools that try to does it. I wrote about it more here: medium.com/@thecodeside/…Chari
I added the plugin to my android's project and then ran the command ./gradlew dependencyUpdates but it kept on scanning for 55 mins but no results, I had to stop it manuallyYork
T
38

See File > Project Structure, then click "Suggestions". I know, this solution was suggested by Hemant Sharma and Jeremías Gersicich, but Android Studio has changed it in 3.4.1 version.

enter image description here

It will help in most cases, but sometimes libraries change their ids (paths). So you should sometimes visit their sites and see why these libraries didn't update so long. Then update manually.

Trainload answered 1/7, 2019 at 13:49 Comment(7)
anyone else getting this screen just empty on android studio 3.5?Propjet
@NicolaBeghin, I have just checked on empty project and got 4 suggestions. Yes, there was a term, when it didn't show suggestions, in July, but they fixed this bug. I suppose, it is Google server problem, it may happen sometimes.Trainload
Doesn't support Gradle KTSLin
Thank you @CoolMind! Any idea why this might not show directly in the build.gradle file for Android Studio 4.2.1? Previously, these suggestions showed through Lint with the setting enabled, i.e. Settings > Editor > Inspections > Newer Library Versions Available.Collbaith
@AdamHurwitz, thank you for your comment! You are right, I have just checked, this window infinitely loads and doesn't show updates. I will test later.Trainload
Awesome @CoolMind, I've created a new post, Android Studio Not Showing Suggested Gradle Dependency Updates With Lint in order to resolve this.Collbaith
In my case in Android Studio 4.2.1 Suggestions show updates for app module, not <All modules>.Trainload
C
15

DEPRECATED - SEE ACCEPTED ANSWER FOR MODERN WAY

The tool I present below doesn't work on new versions of Android Studio / Gradle and its author no longer maintains it (as of 30/10/2016). Therefore, the solution presented in the accepted answer should be used unless working with old version of Android Studio.


As of January 2016, there's a plugin for Android Studio that does something similar, called Dependencies Version Checker, and whose sources can be found on GitHub.

It can be added through the built-in interface (Settings > Plugins > Browse repositories...) :

What it looks like inside the native interface

After installation and restart, the following tab appears in the UI:

New UI tab which appears after restart.

The relevant build.gradle should then be pasted into the left side of the VersionChecker panel, and the Version Check button pressed. The result is a table that appears on the right side, which includes the latest versions of the libraries used in the pasted script (as shown in the image above).

Calculated answered 16/1, 2016 at 16:39 Comment(3)
Even if this is what I was looking in the first place, it doesn't work as expected. I've opened an issue in the Github repo about it. github.com/takuaraki/DependenciesVersionChecker/issues/5Scorpaenoid
I tried this and got a generic error/failure message balloon when I clicked "check versions"Dooley
@GregEnnis There's a problem with the latest version of the plugin. Either use an older one or wait for an update...Calculated
E
6

Go to Android Studio -> Preferences -> Plugins (for Mac) and File -> Settings -> Plugins (for windows) and search “Check for Dependency updates plugin”. Install it and restart android studio. You will be able to see Dependencies tab on the right which will show if any dependency has a new update available.

enter image description here

Exclaim answered 22/6, 2021 at 4:45 Comment(3)
This plugin does not show updates for all dependencies o.O (e.g. exoplayer..)Gist
It shows only dependencies marked as testImplementation for me.Affix
Does not work...Interdisciplinary
S
2

For support library (com.android.support) dependencies, there is a better option - andle

It can query jcenter and maven center as well.

Simple three step to update all project at once.

1. install:

    $ sudo pip install andle

2. set sdk:

    $ andle setsdk -p <sdk_path>

3. update depedency:

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

--dryrun: only print result in console

--remote: check version in jcenter and mavenCentral

--gradle: check gradle version

See https://github.com/Jintin/andle for more information

Stendhal answered 12/10, 2015 at 14:54 Comment(2)
only for support libraries?Scorpaenoid
@Scorpaenoid if you add --remote or -r it will parse the version on jcenter.Stendhal
P
2

I was dealing with this same problem and tried the answer https://mcmap.net/q/107894/-how-to-check-if-gradle-dependency-has-new-version

What really worked for me on Android Studio 3.4.1 was:

File -> Project Structure -> Dependencies

Once you have reached this point all dependencies that are included on your project or module will be listed. The ones that are outdated will be underscored and when you select one, the details of it will be shown giving you the options to updated the Variable (if you have it separated from the declaration) or the Dependency.

Kind of late but this was what worked for me.

Pokey answered 10/6, 2019 at 23:57 Comment(1)
I also found this way. Strange that somebody marked minus.Trainload
D
1

You can use Gradle refreshVersions. It generates a java properties file that tells you what versions are available and lets you change the version number in all dependency instances. So you only edit this file if you ever need to change a dependency's version.

The java properties file, versions.properties, looks something like this.

Decaliter answered 21/11, 2021 at 5:17 Comment(0)
I
0

I tried different libraries but could not find one that I like. Some require you to migrate your code, some require to run via the command line. So I made a Gradle plugin that add updates to comments. Minimize the modification of your codes. https://github.com/zeroarst/dependency-updates-commenter

Example:

Before

object Junit {
    const val junit = "junit:junit:4.12"
}

After

import io.github.zeroarst.dependencyupdatescommenter.CommentUpdates

object Junit {
    // Available versions:
    // 4.13-rc-2
    // 4.13-rc-1
    // 4.13-beta-3
    // 4.13-beta-2
    // 4.13-beta-1
    @CommentUpdates
    const val junit = "junit:junit:4.12"
}
Interdisciplinary answered 30/1, 2023 at 4:54 Comment(0)
T
-1

To get updated or recommended for your project dependency should be same as android project

FILE -> Project Structure -> MODULES(app) -> Dependencies

When you reach the dependencies tab Click on + button which is placed on the top right corner of the window. When you click on + Select Library Dependency it will open New window for Choose Library Dependency Search for your dependency in the search box, all the listed Android dependencies are updated.

Travis answered 7/8, 2018 at 5:54 Comment(2)
Thanks, but this list also contains libraries I don't use and sometimes doesn't contain what I use. Also Gson is com.google.code.gson:gson:2.2.4 while actually it is com.google.code.gson:gson:2.8.5Trainload
sometimes dependencies work with compatible gradle version, Please check if you are using updated gradle in your Project level gradleTravis

© 2022 - 2024 — McMap. All rights reserved.