在我初次使用用idea
打开Android
项目的时候,总会出现gradle
sync
出现问题,然后每次都是try
again
.最后都是不行.
后来找到了解决办法
先在idea
的settings
里搜索gradle
如下图所示
然后选择Use default Gradle wrapper(recommended)
在这里选择第一个后发现Gradle home
是灰色的,是不能选择的.
在文件build.gradle
中加上maven{}
buildscript {
repositories {
jcenter()
maven {
url "http://maven.aliyun.com/nexus/content/groups/public/"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven {
url "http://maven.aliyun.com/nexus/content/groups/public/"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
然后重新同步,不过过程过程会有点慢.因为要在网上下载适配的gradle版本.有可能原本项目的classpath 'com.android.tools.build:gradle:3.1.0'
的版本可能会有点低,更新也不行.可以换成比较新的版本.
亲测可行