您的位置:首页 > 其它

解决Error:Unable to find method 'org.gradle.api.internal.project.ProjectInternal.

2016-10-20 21:55 621 查看
http://blog.csdn.net/ouyang_peng/article/details/52027668
http://blog.csdn.net/ouyang_peng/article/details/52027668 http://blog.csdn.net/ouyang_peng/article/details/52027668 http://blog.csdn.net/ouyang_peng/article/details/52027668
 


我的Android进阶之旅------>解决Error:Unable to find method 'org.gradle.api.internal.project.ProjectInternal.g

2016-07-25 21:22 1049人阅读 评论(0) 收藏 举报

版权声明:本文为【欧阳鹏】原创文章,欢迎转载,转载请注明出处! 【http://blog.csdn.net/ouyang_peng】

目录(?)[+]

错误描述

今天在Github上面下载了一份代码,然后导入到Android Studio中直接报了如下图所示的错误: 



错误描述如下:

Error: Unable to find method ‘org.gradle.api.internal.project.ProjectInternal.getPluginManager()Lorg/gradle/api/internal/plugins/PluginManagerInternal;’.

Possible causes for this unexpected error include:

Gradle’s dependency cache may be corrupt (this sometimes occurs after a network connection timeout.) 
Re-download dependencies and sync project (requires network)

The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem. 
Stop Gradle build processes (requires restart)

Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.

In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

解决方法

按照如上图所示的提示去点击【Re-download dependencies and sync project】选项,发现怎么重新尝试还是无效果。如果点击【Stop Gradle build processes (requires restart)】选项,则直接退出了Android Studio,重启后还是无效。

最后我把该Github上面下载下来的代码和我已经运行正常的代码做对比,发现有两个地方的代码有很大的差异:

差异一:gradle版本太低

发现该代码的gradle版本为1.2.3,代码如下
<code class="hljs bash has-numbering" style="display: block; padding: 0px; background: transparent; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal;">   classpath <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'com.android.tools.build:gradle:1.2.3'</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right: 1px solid rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right: 1px solid rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>


因为gradle版本为1.2.3我电脑上没有下载,因此我将gradle版本改为我目前Android Studio中所使用的gradle版本2.2.0-alpha4’,代码如下:
<code class="hljs bash has-numbering" style="display: block; padding: 0px; background: transparent; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal;">    classpath <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'com.android.tools.build:gradle:2.2.0-alpha4'</span>
//  classpath <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'com.android.tools.build:gradle:1.2.3'</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right: 1px solid rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right: 1px solid rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li></ul>


差异二:gradle-wrapper.properties里面的gradle压缩包版本太低

发现了项目工程文件目录gradle\wrapper里面找到gradle-wrapper.properties里面的内容不同。

位置如下图所示: 



修改里面的值:将distributionUrl=https://services.gradle.org/distributions/gradle-2.2-all.zip改为distributionUrl=https://services.gradle.org/distributions/gradle-2.10-all.zip 。如下所示: 



<code class="hljs ruby has-numbering" style="display: block; padding: 0px; background: transparent; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal;">distributionUrl=https\<span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">://services</span>.gradle.org/distributions/gradle-<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2.2</span>-all.zip</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right: 1px solid rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right: 1px solid rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>


改为:
<code class="hljs ruby has-numbering" style="display: block; padding: 0px; background: transparent; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal;">distributionUrl=https\<span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">://services</span>.gradle.org/distributions/gradle-<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2.10</span>-all.zip</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right: 1px solid rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right: 1px solid rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>


修改后如下图所示: 



<code class="hljs makefile has-numbering" style="display: block; padding: 0px; background: transparent; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal;"><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#Mon Jul 25 20:23:10 CST 2016</span>
<span class="hljs-constant" style="box-sizing: border-box;">distributionBase</span>=GRADLE_USER_HOME
<span class="hljs-constant" style="box-sizing: border-box;">distributionPath</span>=wrapper/dists
<span class="hljs-constant" style="box-sizing: border-box;">zipStoreBase</span>=GRADLE_USER_HOME
<span class="hljs-constant" style="box-sizing: border-box;">zipStorePath</span>=wrapper/dists
<span class="hljs-constant" style="box-sizing: border-box;">distributionUrl</span>=https\://services.gradle.org/distributions/gradle-2.10-all.zip</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right: 1px solid rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right: 1px solid rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li></ul>


修改完之后,再重新编译即可。编译成功后,如下图所示: 



作者:欧阳鹏 欢迎转载,与人分享是进步的源泉! 

转载请保留原文地址:http://blog.csdn.net/ouyang_peng
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐