android studio编译运行报错(一)

来源:互联网 发布:java源码阅读 编辑:程序博客网 时间:2024/04/30 01:05

     记录一下自己使用studio中遇到的问题以及解决办法,后面再遇到问题也会记录到这里,把遇到的问题解决,就是经验。

一、android studio引用远程仓库下载慢(JCenter下载慢)

     有时候我们在创建工程 或者 导入其他工程时,界面上就显示一个进度条,进度条上面还显示着Download https://jcenter.bintray.com/,一直在这卡着,等半天也不见好,这是因为需要翻墙才行。如果无法翻墙,那就将https协议改为http协议即可。具体操作是:

替换项目根目录下build.gradle中的
  repositories {
      jcenter()
  }
为:
  repositories {
      jcenter(){ url ‘http://jcenter.bintray.com/‘}
  }

二、android studio在sync时报错如下:

Error:Connection timed out: connect.

那么一般是因为错误发生在构建Gradle的过程中正在下载gradle.zip文件的时候,估计应该是访问地址被墙了,而下载不了该文件。

可以直接先把对应的gradle.zip文件下载下来,放入正确的文件夹即可。

我是这么解决的:原来的根目录:

classpath ‘com.android.tools.build:gradle:2.3.3’

然后报这个错,但是我确定的是本地有gradle:2.2.3。
所以我把上面根目录下的gradle:2.3.3改为gradle:2.2.3,然后再次sync,成功。

三、studio突然就挂掉了,重新打开之后无法运行工程。
报错如下:

Unknown run configuration type AndroidRunConfigurationType

打开File->settings->Plugins,发现只有Android support没有勾选,那就把这一项勾选上,然后Apply,如果Apply没反应,那就把其他的项先勾掉,然后再勾选,最后确保所有项都勾选了,然后Apply,点击OK即可。

这里写图片描述

四、当时在解决完第三个问题后,本以为万事大吉,但是又报错了。。。

    报错如下:

Error:Failed to complete Gradle execution.
Cause:
Write access is allowed from event dispatch thread only

就各种找解决方案,最后在Stackoverflow中找到解决方案:

So the problem was concluded in that android studio conflicted with my installed jdk version, so it was resolved when i checked jdk location (Project Structure -> SDK Location), ticked ‘Use embedded JDK’ checkbox and set jdk location to ‘path to android studio’\Android Studio\jre

意思就是:

给当前的android studio的jdk换个版本,使用android studio 自带的jre。JDK版本 和 sdk版本冲突。

具体操作:
File->Project Structure,以图示意:

这里写图片描述

设置JDK路径:

这里写图片描述

勾选:Use embedded JDK (recommended)

ok,至此,这个问题解决。