天天看点

gradle DSL method not found: android()错误解决办法

今天用android studio导入项目的时候出现了各种问题 先记录下免得以后忘记

首先是要求的sdk APi版本没有  我就拿了个高一点的 但是引入之后又提示gradle DSL method not found: android()

我英语也不行 大概就是没有找到android();这个后面还给了两个解决办法 可是一点都不管用,然后用百度搜了一下,这个问题可能碰到的人少还是怎么的 中文的就没搜到,然后就翻了一下用了下谷歌一搜还真有,我先给出链接

https://medium.com/@marcuspereira/solving-the-gradle-dsl-method-not-found-android-in-android-studio-6e5ab499bd3 

这个就是   我刚刚试了一下  不用翻直接就能打开  对百度很是失望啊。上面都是英文 不太难

主要的我翻译一下

For a unknown reason, Android Studio incorrectly adds the android() method in the top-level build.gradle file.

Note that is this build.gradle file. Usually, there’s another file with the same name inside the app folder.

Just delete the method.

//DELETE THIS LINES:android {    compileSdkVersion 21    buildToolsVersion '21.1.2'}

Try to compile again. It should work now.

因为一些不知道的原因,android studio 错误的把android()方法加到了top-level build.gradle中,所以这个解决方法相当简单 就是把top-level  build.gradle(有两个文件   记住 是项目名/build.gradle这个)打开之后删除

android {    compileSdkVersion 21    buildToolsVersion '21.1.2'}这句代码  然后  try again  就解决了

我用android studio没两天  至于为什么这样我也不清楚 。 

很是膜拜解决了这个的人。

继续阅读