build.gradle dependencies auto updates itself

*爱你&永不变心* 提交于 2019-12-23 12:28:10

问题


compile 'com.google.android.gms:play-services:8.3.0'
compile 'com.android.support:support-v4:22.2.1'
compile 'com.android.support:design:22.2.1'

to

compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.android.support:support-v4:23.1.0'
compile 'com.android.support:design:23.1.0'

Time to time, android studio will automatically change the values to the latest version which is extremely annoying and breaks my application. Is there a way to prevent this from happening?

Did a google search and stackoverflow searched but nothing came up.


回答1:


Instead of:

compile 'com.google.android.gms:play-services:8.3.0'
compile 'com.android.support:support-v4:22.2.1'
compile 'com.android.support:design:22.2.1'

try:

playVersion = '8.3.0'
supportVersion = 'support-v4:22.2.1'
designVersion = '22.2.1'
compile "com.google.android.gms:play-services:$playVersion"
compile "com.android.support:$supportVersion"
compile "com.android.support:design:$designVersion"

Remember to replace the 's with "s.




回答2:


Android Studio doesn't update the dependencies if you specify the version

Example:

compile 'com.google.android.gms:play-services:8.3.0'
compile 'com.android.support:support-v4:22.2.1'
compile 'com.android.support:design:22.2.1'

In this case AS will tell you when there is a newer version without updating them.

If you the + in your dependencies gradle updates with the latest version according to the build.gradle.
For example:

compile 'com.android.support:support-v4:22.2.+'
compile 'com.android.support:support-v4:22.+'
compile 'com.android.support:support-v4:+'

It is a good practice to avoid it.




回答3:


I just ran into this with another developer who had checked out my project, and then started getting build errors shortly thereafter. When I looked, my support library versions had appeared to have been updated as well.

Turns out this was happening after they had added a new Activity via the Android Studio add an activity wizard. This was automatically updating the build.gradle file to use the latest support library versions, and also adding the 'com.android.support:design:23.2.0' library as well which I wasn't even using.

I'm wondering if something similar is happening to you, as you are indicating it seems to be periodically happening.



来源:https://stackoverflow.com/questions/35063889/build-gradle-dependencies-auto-updates-itself

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