如何检查gradle依赖项是否具有新版本

时间:2015-02-23 20:59:16

标签: android-studio gradle

在Android Studio中,当我在版本号中使用+时(如com.android.support:recyclerview-v7:21.+),我会收到“避免在版本号中使用+”警告。当我使用特定版本号时,我不能总是使用最新版本。我的项目中有很多依赖项。如何检查依赖项是否具有较新版本?是否有Android Studio插件 - 或类似的东西 - 在有更新版本的依赖项时通知我?

修改 Android工作室突出了过时的Android支持库和Google Play服务。但是这不适用于其他自定义库。

enter image description here

9 个答案:

答案 0 :(得分:260)

更新(05/23/18):

较新版本的Android Studio未在“项目结构”对话框中显示版本更新。相反,亚当的答案是Android Studio 3 +的正确答案

  

分析> "按名称运行检查"

然后搜索" Newer Library Versions Available"

以前的方式:

Android Studio 2.2开始,新的Project Structure对话框会显示您的应用正在使用的依赖关系列表以及来自本地和远程存储库的可用更新。

  • 转到Android Studio > Settings > Build, Execution, Deployment > Gradle > Experimental并检查Use new Project Structure dialog(感谢@jessehensold)
  • 来激活它
  • 然后转到File > Project Structure > Messages
  • 打开它

enter image description here

对于旧版Android Studio,请参阅下面的其他回复。

答案 1 :(得分:144)

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).

答案 2 :(得分:32)

除了Android Studio的内置功能之外,还有一个名为Gradle Versions Plugin的漂亮的gradle插件可以完全满足您的需求,并且具有普通的gradle扩展功能,因此不会与任何特定的IDE绑定,因此对任何特定的IDE都有用。项目使用Gradle。

Gradle Versions Plugin可以以人类可读的纯文本格式创建报表,但也可以将其转储为JSON或XML以进行自动处理。

一旦添加到您的gradle文件,标准用法看起来更像是:

> ./gradlew dependencyUpdates

这将产生如下所示的项目依赖性报告:

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

The following dependencies are using the latest milestone version:
 - com.github.maksim88:PasswordEditText:v0.9
 - com.android.databinding:adapters:1.3.1
 - com.joanzapata.iconify:android-iconify-entypo:2.2.2
 - com.joanzapata.iconify:android-iconify-fontawesome:2.2.2
 - com.webnetmobile.tools: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

有关广泛的使用示例,请参阅docs

注意:高于0.17.0的版本会以平面文本格式生成更多输出,包括项目URL因此使整个输出膨胀。如果你,因为我觉得没用,坚持使用版本0.17.0。

答案 3 :(得分:13)

已弃用 - SEE ACCEPTED ANSWER现代方式

我在下面提供的工具不适用于Android Studio / Gradle的新版本,其作者不再维护它(as of 30/10/2016)。因此,除非使用旧版Android Studio,否则应使用中提供的解决方案。

截至2016年1月,有一个Android Studio插件可以执行类似的操作,名为 Dependencies Version Checker ,其源代码可以在GitHub找到。

可以通过内置界面添加(设置&gt;插件&gt;浏览存储库...):

What it looks like inside the native interface

安装并重新启动后,UI中将显示以下选项卡:

New UI tab which appears after restart.

然后应将相关的build.gradle粘贴到VersionChecker面板的左侧,并按下 Version Check 按钮。结果是显示在右侧的表格,其中包括粘贴脚本中使用的最新版本的库(如上图所示)。

答案 4 :(得分:2)

请参阅“文件”>“项目结构”,然后单击“建议”。我知道,这个解决方案是由Hemant Sharma和JeremíasGersicich提出的,但Android Studio已在3.4.1版本中对其进行了更改。

enter image description here

答案 5 :(得分:1)

对于支持库(com.android.support)依赖项,有一个更好的选择 - andle

它也可以查询jcenter和maven中心。

一步更新所有项目的简单三步。

<强> 1。安装:

    $ sudo pip install andle

<强> 2。设置sdk:

    $ andle setsdk -p <sdk_path>

第3。更新依赖性:

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

- dryrun:仅在控制台中打印结果

- remote:检查jcenter和mavenCentral中的版本

- gradle:检查gradle版本

有关详细信息,请参阅https://github.com/Jintin/andle

答案 6 :(得分:0)

我正在处理同样的问题,并尝试了答案pg_hba.conf

在Android Studio 3.4.1上对我真正起作用的是:

File -> Project Structure -> Dependencies

到此为止,将列出项目或模块中包含的所有依赖项。过时的将突出显示,当您选择一个时,将显示其详细信息,为您提供更新变量(如果您将其与声明分开)或依赖项的选项。

最近有点,但这对我有用。

答案 7 :(得分:0)

转到 Android Studio -> 首选项 -> 插件(适用于 Mac)和文件 -> 设置 -> 插件(适用于 Windows)并搜索“Check for Dependency updates plugin”。 安装它并重新启动android studio。您将能够在右侧看到“依赖项”选项卡,该选项卡将显示任何依赖项是否有可用的新更新。

enter image description here

答案 8 :(得分:-1)

要获得更新或建议的项目依赖项,应与android项目相同

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

到达依赖项选项卡时,单击位于窗口右上角的+按钮。 当您点击+选择Library Dependency时,它将打开Choose Library Dependency的新窗口在搜索框中搜索您的依赖项,所有列出的Android依赖项都会更新。