本来刚升级studio到1.0的时候就想写这篇文章的,但是没空就没写了。
好吧,今天把这个问题写下,因为很多同事也遇到这个问题,解决不了,在你把Android studio升级到1.0后,你会发现你的gradle sync的时候会报底下这个错:
报这个错的原因其实是因为你在升级完后,然后工程会默认把你的gradle版本替换成最新的版本,所以你的build.gradle文件中的dependencies也变成最新的了,如下:
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0-rc1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
那为啥变成最新的就不行了,其实这个我觉得是gradle团队可能不是那么强大的原因吧,新版本可能没有做到向下兼容旧版本...其实看报错就知道了,runProguard()找不着了。以前也有出现过0.12到0.14后 "useOldManifestMerger“找不到的问题。
要让sync成功,改下gradle的版本就可以了,如下:
dependencies {
classpath 'com.android.tools.build:gradle:0.14.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
PS,感谢ohskean的提醒,我这边也将他提供的方法加到文章来,
old:
<code style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, serif; white-space: inherit;"><span class="pln" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;">buildTypes </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;">{</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;"> release </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;">{</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;"> <span style="color: rgb(255, 0, 0);">runProguard </span></span><span class="kwd" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;"><span style="color: rgb(255, 0, 0);">false</span></span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;"> </span><span class="com" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; color: rgb(128, 128, 128); background: transparent;">// 已经被废弃并且停止使用了</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;"> ......</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;"> </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;">}</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;"> </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;">}</span></code>
new:
<code style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, serif; white-space: inherit;"><span class="pln" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;">buildTypes </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;">{</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;"> release </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;">{</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;"> <span style="color: rgb(255, 0, 0);">minifyEnabled </span></span><span class="kwd" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;"><span style="color: rgb(255, 0, 0);">false</span></span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;"> </span><span class="com" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; color: rgb(128, 128, 128); background: transparent;">// 替代的方式</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;"> ......</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;"> </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;">}</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;"> </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;">}</span></code>