最近安装了Android Studio的181.5014246版本,发现无法预览xml文件和布局,原因是gradle没有同步,查了一下资料,按照下面的操作配置和更新:
-
创建工程或导入工程,在工程界面按Shift + Ctrl + A搜索sync,选择Sync Project with Gradle Files
-
出现第一个错误,提示没有权限,推测可能是没有权限访问Gradle网站,现在Gradle更新的地址都是https的,需要ssl认证,这时可以去手动下载,具体对应哪个版本需要根据工程来确认。
可以按照下面的方法解决:
修改工程中的\gradle\wrapper\gradle-wrapper.properties文件,将distributionUrl改为本地地址,如:file:///D:/gradle-4.6-all.zip
-
再次更新,还是会报jcenter的错误,应该还是提示权限问题,原因和上面的类似。
可以按照下面的方法解决:
修改工程中的\build.gradle文件,在两个repositories下添加国内的镜像: maven{url’http://maven.aliyun.com/nexus/content/groups/public/’ }
maven{url’http://maven.aliyun.com/nexus/content/repositories/jcenter’}
屏蔽之前的jcenter(),如:// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { google() maven{ url'http://maven.aliyun.com/nexus/content/groups/public/' } maven{ url'http://maven.aliyun.com/nexus/content/repositories/jcenter'} // jcenter(){ url 'http://jcenter.bintray.com/'} } dependencies { classpath 'com.android.tools.build:gradle:3.2.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { google() maven{ url'http://maven.aliyun.com/nexus/content/groups/public/' } maven{ url'http://maven.aliyun.com/nexus/content/repositories/jcenter'} // jcenter() } } task clean(type: Delete) { delete rootProject.buildDir }
- 再次Sync Project with Gradle Files就可以了
上面只是提供一种思路,具体还是得根据错误具体分析和解决。
解决Android Studio预览XML布局问题
605

被折叠的 条评论
为什么被折叠?



