简体   繁体   English

如何检查要在 gradle 中使用的最新版本的依赖项

[英]How to check what is the latest version of a dependency to use in gradle

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.但是在最新版本的 Android Studio 中,他们建议不要使用+因为它会导致错误。 How to know what's the latest version?如何知道最新版本是什么? I can try every combination of 19.yx until gradle complains, but what's the real way do check?我可以尝试 19.yx 的所有组合,直到 gradle 抱怨为止,但真正的检查方法是什么?

edit: sometimes, that page helps me figure it out.编辑:有时,该页面可以帮助我弄清楚。

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.您可以通过在 build.gradle 编译行中替换库的版本号,使用 Android Studio 找到最新版本,只需+ ,然后单击窗口右上角的Sync Now

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 + . Android Studio 会弹出一个提示/灯泡,其中有选项Replace with specific version您可以单击的Replace with specific version ,它将代替+填写最新版本。 Please see below screeshot:请看下面的截图:

安卓工作室提示

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).如果这在第一次不起作用,让 gradle 完成它的同步,然后重试(用 + 替换 + 或任何文件修改都可以,再次单击同步并提示灯泡将出现)。

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例如,对于您的库,我只是将这一行compile 'com.android.support:mediarouter-v7:+'粘贴到我的依赖项下并按照上述过程进行操作,Android Studio 中填充了以下版本

.

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 .了解库的新版本何时发布的最简单方法是在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.然后,您将能够更新依赖项,对其进行测试,然后才使用新版本提交构建脚本。

在 Bintray 中观看包

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.使用 android studio 2.2 及更高版本,项目结构将向您展示可用的最新依赖项。

  1. Activate it by going to Android Studio > Settings > Build, Execution, Deployment > Gradle > Experimental and check the Use new Project Structure dialog通过转到 Android Studio > Settings > Build, Execution, Deployment > Gradle > Experimental 激活它并检查 Use new Project Structure 对话框
  2. Then open it by going to File >Project Structure >然后通过转到文件>项目结构>打开它显示更新对话框的图像 Messages留言

Original Answer原答案

I use these two links.我使用这两个链接。

This link gives me the latest buildTools Version这个链接给了我最新的 buildTools 版本
https://developer.android.com/studio/releases/build-tools.html 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这个链接给了我最新的 supportLibraryVersion https://developer.android.com/topic/libraries/support-library/revisions.html

Recently, I have found this.最近,我发现了这个。

Go to File -> Project Structure转到File -> Project Structure

Select the Module , where you want to add the dependency.选择要添加依赖项的Module

Go to the Dependencies Tab转到Dependencies选项卡

Click + and Choose Library Dependency单击+并选择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.谢谢你。

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.您可以尝试使用andle检查依赖项是否已过期,以及构建工具版本和 sdk 版本。

Simple three step:简单三步:

1. install: 1.安装:

    $ sudo pip install andle

2. set sdk: 2.设置sdk:

    $ andle setsdk -p <sdk_path>

3. update depedency: 3.更新依赖:

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

--dryrun: only print result in console --dryrun: 只在控制台打印结果

--remote: check version in jcenter and mavenCentral --remote: 检查 jcenter 和 mavenCentral 中的版本

the answer of ashoke is correct if you want the latest version.如果您想要最新版本,ashoke 的答案是正确的。

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) (但不使用 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."然后查找“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" “使用来自 Maven 存储库的 com.android.support:appcompat-v7:21.0.3”

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.如果它是来自 Google 的 maven 存储库的依赖项,那么现在最好的方法是访问https://maven.google.com ,在那里 google 现在可以让您浏览其所有库并查看所有可用版本,包括最新版本版本。 It looks like this:它看起来像这样:

在此处输入图片说明

You can even do a search for a specific library, and then expand/collapse it as desired:您甚至可以搜索特定库,然后根据需要展开/折叠它:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM