您的位置:首页 > 移动开发 > Android开发

【经验】Android Gradle配置问题

2016-04-03 21:18 435 查看
翻墙后搞了一天Gradle,到处找资料,结果都不行,记录一点经验,以备之后再次出错

一、有时,配置Gradle出现如下错误

Gradle DSL method not found:'android()'




偶然间stackoverflow上找到个可用的方法,先看看下面我的build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-rc1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

android {
compileSdkVersion 22
buildToolsVersion '23.0.3'
}


解决这个问题,只要把allprojects{}之后的东西全部删掉即可

如下所示

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-rc1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}


二、git clone下来的文件在AS中使用时,经常性卡在gradle里,尝试了下解决方法,大致如下,很大机会能保证正常编译,但不100%保证能编译成功

1.在工程目录下有gradle/wrapper/gradle-wrapper.properties文件,其中有一句类似于

distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip修改其中gradle-xx.zip的版本号,改为你现在有的
2.其中下面gradle版本号也改为你能用的一个(新建一个项目,看看里面对应的用的是哪个版本)dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-rc1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
3.另外,此处版本也相应改为和1处相同的版本
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: