吃水不忘网挖井人 转自简书:http://www.jianshu.com/p/00beddbe3dbc
step1
打开一个项目,在Studio中选择Project的视图,找到目录gradle\wrapper\gradle-wrapper.properties这个文件。打开可以看到以下内容
![](http://upload-images.jianshu.io/upload_images/1638147-fbd3b554d4e743fa.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](http://upload-images.jianshu.io/upload_images/1638147-7a6d9afdc163a318.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
直接看最后一行,可以看到当前版本是2.4
Step2
若需要升级到Gradle2.10,只要将版本改为2.10,如下图
![](http://upload-images.jianshu.io/upload_images/1638147-1172795cd9607257.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
关掉Studio重新打开该项目
在C盘下找到自己的用户目录,进入.gradle\wrapper\dists文件夹。
如:C:\Users\Gavin.gradle\wrapper\dists
在这里可以看到gradle-2.10-all文件夹(若无该目录,请看Tip1)
![](http://upload-images.jianshu.io/upload_images/1638147-f1ca9d44d98673d9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
这个gradle-2.10-all就是我们需要的Gradle版本了。
进入gradle-2.10-all文件夹,可以看到以下文件
![](http://upload-images.jianshu.io/upload_images/1638147-8f9f3314b38e915d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
目录下出现a4w5fzrkeut1ox71xslb49gst(可能会不一样),点击进入。记住这个目录,等下要用到
![](http://upload-images.jianshu.io/upload_images/1638147-1dfdef59a2d657a6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
Step3
浏览器打开
找到自己需要升级的版本,把对应的下载链接复制下来,通过下载工具下载(我这边用的是迅雷),不然很慢。
例如:我需要的是2.10版本,对应的连接就是
http://services.gradle.org/distributions/gradle-2.10-all.zip
这样很快就下载好了,完成后会得到这样的一个压缩文件
![](http://upload-images.jianshu.io/upload_images/1638147-0dfc47acb4bba094.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
把文件放到刚刚提到的目录下(不要解压)
C:\Users\Gavin.gradle\wrapper\dists\gradle-2.10-all\a4w5fzrkeut1ox71xslb49gst
![](http://upload-images.jianshu.io/upload_images/1638147-110942f92b019895.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
Step4
修改Project下的build中的classpath
![](http://upload-images.jianshu.io/upload_images/1638147-fc174655a57344df.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
把原来的
![](http://upload-images.jianshu.io/upload_images/1638147-10bd592cc653bed4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
改为
![](http://upload-images.jianshu.io/upload_images/1638147-218dd4fe3af5265e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
(这里2.10的Gradle对应的是2.0.0,具体的对照关系我还不是很清楚。敬请指教)
Step5
重新关闭Studio重新打开
或
直接单击Studio工具栏 Sync Project Gradle Files就可以了
![](http://upload-images.jianshu.io/upload_images/1638147-cb6b4aaf8238e8a9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)