Android Studio问题:Gradle DSL method not found: ‘android()’

下载个例子,在Android Studio中打开,错误N多,这个错误如下:

Gradle DSL method not found: ‘android()’

在stackoverflow上有很好的回答:

http://stackoverflow.com/questions/27735646/android-studio-gradle-dsl-method-not-found-android-error17-0

解决方法:

在项目顶层(根目录)的build.gradle中,有下面的代码,其实是不行的:

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"
}

这些代码其实是在打开模块属性对话框,设置了“Compile Sdk Version”和“Build Tools Version”之后,自动在顶层build.gradle中生成的,坑人。其实,如果这个对话框中左侧的模块中,如果有app模块,那么修改的属性应该就插入到app/build.gradle中了。

把这些删掉,重新刷新就可以了。

此外,在顶层的build.gradle中,下面这些依赖的代码也是不可以有的,否则会出现错误:Gradle Dsl method not found compile()

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.2.0'
    compile 'com.android.support:design:23.2.0'
}
这些都只能在项目中模块(如app)的build.gradle中。



  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值