android studio在编辑时出现如Failed to sync Gradle project类似的问题时的解决方案
来源:互联网 发布:网络优化需要培训费吗 编辑:程序博客网 时间:2024/05/18 00:24
最近使用android studio发现环境坏了,提示如下:
Failedto sync Gradle project’XXXXX’
Error:Unable to load class'asLocalRepo0_1r7i3nvnipez3xbls4oy6h797'.
Possible causes for this unexpected errorinclude:<ul><li>You are using JDK version 'java version"1.7.0_67"'. Some versions of JDK 1.7 (e.g. 1.7.0_10) may cause classloading errors in Gradle.
Please update to a newer version (e.g.1.7.0_67).
<a href="open.project.structure">OpenJDK Settings</a></li><li>Gradle's dependency cache may becorrupt (this sometimes occurs after a network connection timeout.)
<ahref="syncProject">Re-download dependencies and sync project(requires network)</a></li><li>The state of a Gradle buildprocess (daemon) may be corrupt. Stopping all Gradle daemons may solve thisproblem.
<ahref="stopGradleDaemons">Stop Gradle build processes (requiresrestart)</a></li><li>Your project may be using a third-partyplugin which is not compatible with the other plugins in the project or theversion of Gradle requested by the project.</li></ul>In the case ofcorrupt Gradle processes, you can also try closing the IDE and then killing allJava processes.
按上面的意思,可能是jdk出问题了,所以查看了一下自己的jdk版本:1.7.0.67,已经是了呀,后来我读这段英语才明白,它的意思是jdk1.7(无论是1.7.0_10还是1.7.0.67,还是别的1.7.XXX)类型的可能都会导致使用Gradle工具类加载错误,所以就去下载个最新版的吧,我写的现在最新版是jdk 1.8,下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
如图:
安装配置请参考:http://jingyan.baidu.com/article/f96699bb8b38e0894e3c1bef.html
对于下载安装配置完jdk1.8,我在项目目录\app\build.gradle里面写的还是1.7:
sourceCompatibilityJavaVersion.VERSION_1_7
targetCompatibilityJavaVersion.VERSION_1_7
一开始是我写成了1.8的如:
sourceCompatibilityJavaVersion.VERSION_1_8
targetCompatibilityJavaVersion.VERSION_1_8
报了很多莫名其妙的错如:
UNEXPECTEDTOP-LEVEL EXCEPTION:
Error:com.android.dx.cf.iface.ParseException:bad class file magic (cafebabe) or version (0034.0000)
atcom.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)
atcom.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
atcom.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
atcom.android.dx.command.dexer.Main.parseClass(Main.java:764)
at com.android.dx.command.dexer.Main.access$1500(Main.java:85)
atcom.android.dx.command.dexer.Main$ClassParserTask.call(Main.java:1684)
atcom.android.dx.command.dexer.Main.processClass(Main.java:749)
... 19 more
出现这种错,可能是jdk1.8虽然比jdk1.7更兼容,但他们使用的某些库和函数差别比较,当然有兄弟知道的更多的,也请告诉我一声,谢谢了。
然后再重新加载时就少了这个错,
<a href="open.project.structure">OpenJDK Settings</a></li><li>Gradle's dependency cache may becorrupt (this sometimes occurs after a network connection timeout.)
<ahref="syncProject">Re-download dependencies and sync project(requires network)</a></li><li>The state of a Gradle buildprocess (daemon) may be corrupt. Stopping all Gradle daemons may solve thisproblem.
<ahref="stopGradleDaemons">Stop Gradle build processes (requiresrestart)</a></li><li>Your project may be using a third-partyplugin which is not compatible with the other plugins in the project or theversion of Gradle requested by the project.</li></ul>In the case ofcorrupt Gradle processes, you can also try closing the IDE and then killing allJava processes.
对于这个问题,观察和猜想,关键应该是这句话:Your project may be using a third-party plugin which is notcompatible with the other plugins in the project or the version of Gradlerequested by the project,我的理解就是插件不兼容,再看看了官网,然后把咱们的项目下的build.gradle下面的改成最新的,我的是改成这样:
再设置一下:项目目录\gradle\wrapper\gradle-wrapper.properties这个文件的distributionUrl=https\://services.gradle.org/distributions/gradle-2.9-all.zip,如果不知道设置成什么的话,就设置比较新吧,那么怎么知道现在有哪些新的gradle包呢?请访问这个地址:
https://services.gradle.org/distributions/如下图:
我选择的是第二个,再重新编译就没有这个问题了,不过,我又出现新问题了:
……
Error:(17, 0) Gradle DSL method not found: 'android()'如图
我想了想,发现之前的项目顶级目录的build.gradle这个文件里面只有:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
}
}
allprojects {
repositories {
jcenter()
}
}
所以把这些之外,17行开始android{}的相关内容删除后,就可以了。
- android studio在编辑时出现如Failed to sync Gradle project类似的问题时的解决方案
- Android Studio,“Failed to sync Gradle project 'xxxx' ”的解决
- Android Studio 导入项目的时候出现Failed to sync Gradle project
- Android studio的 gradle project sync failed
- Android Studio从Eclipse工程导入时Failed to sync Gradle project
- 关于android studio错误:gradle project sync failed.please fix your project and try again的解决方案
- Android studio:fail to sync Gradle project '***' 的解决办法
- Android Studio Gradle project sync failed,Gradle sync failed: Unable to start the daemon process.
- Failed to sync Gradle Project "xxx"解决方案
- Android Studio Error: Gradle project sync failed
- Android Studio Gradle project sync failed
- android studio 提示"Gradle project sync failed."
- android studio 提示 “Gradle project sync failed”
- android studio 提示"Gradle project sync failed."
- Android Studio,gradle project sync failed 错误
- 安装Android-studio遇到Gradle sync failed:和出现building“project name”gradle project info
- Android Studio sync build.gradle 出现:Failed to resolve: com.android.support:appcompat 问题
- android studio gradle project sync failed,和android studio Error:Unable to start the daemon process问题
- 导出数据到Excel表(不需要本地安装Office)
- 移动端:active伪类无效的解决方法
- android 一些总结 1.2-1.10
- Echars在bootstrap的tab下切换不能正常显示的问题
- iOS开发实践之多线程(GCD)
- android studio在编辑时出现如Failed to sync Gradle project类似的问题时的解决方案
- PyQt5系列教程(六)如何让界面和逻辑分离
- three.js学习笔记 相机控件
- 从零开始写javaweb框架笔记10-搭建轻量级JAVAWEB框架-确定目标
- 经典C语言程序设计100例
- C/C++基本数据类型所占字节数
- Golang初级系列教程-控制结构-defer语句
- new delete与malloc free之内存管理(1)
- 统计互不相同且无重复数字的三位数个数