build.gradle warning 'avoid using + in version numbers'

被刻印的时光 ゝ 提交于 2019-12-05 10:46:08

Someday, someone else may do a git pull on your code and then try build an apk. This apk may have different behavior or even get a build error or run time error, because the dependencies version can be different than the dependencies used when you created this code.

You should use an explicit dependency version. I suggest use the newest version. You can search on bintray jcenter to see the newest version. If you are using Android Studio, File -> Project Structure -> Modules -> (your module, app usually) -> Dependencies -> Add library dependency (click the + sign) will give you the newest version, even add library automatically.

Replace it with the latest version of the library. Usually AS shows the latest version when you alt + enter on the warning.

More info on the reasons

You can use something like

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

Don't use + in dependency version. it means Android studio will use the latest library, which may cause problem in future. In android studio it's recommended to use all android library with same version, suppose you are using + and if any single library got updated then android studio will use that updated library, so the version for this library will be change. that cause problem to build application.

That's why gradle giving this warning. it's best practice to write full version number instead of +.

Why this warning message?

Here you can find a good blog about this topic.

Dynamic versions add nondeterminism to your build:

  • Dependencies can unexpectedly introduce behavior changes to your app.

  • The same source built on two different machines can differ.

  • Similarly, builds built on the same machine but at different times can differ.

  • Past builds cannot be reproduced perfectly. This makes it difficult to revert safely.

  • There are security implications if a bad actor introduces a malicious version of a dependency.

What I need to write to solve the warning ?

Always specify your dependency versions explicitly.

It's a normal warning.

It's better you to choose a concrete version than going that way. This is because if you use "+" it will choose the newest, so in the new version it's possible you to get some deprecated or unexpected changes that will do your app to die. Think that if you are using it in a huge project you will have a lot of dependencies so it will be a chaotic environment.

Use specific versions and if there is a new one... update it manually.

To solve the warning and choose the last version, if you are using Windows, click Alt+Enter and it will choose the latest version.

If it doesn't work you will have to search for it on the Internet or in Project Structure > Modules >(your module) > Dependencies > +

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!