错误:(22,0)找不到参数的方法android()

时间:2016-11-16 19:08:59

标签: android-studio

我试着运行我的应用程序并得到了这个错误,请帮助我。

// 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.2.0'
        classpath 'com.google.gms:google-services:3.0.0'
        // 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 {
    signingConfigs {
        config {
        }
    }
    buildToolsVersion '24.0.2'
    compileSdkVersion 24
    buildTypes {
        buildType {
            signingConfig signingConfigs.config
        }
    }
}
dependencies {
}

错误:

  

错误:(22,0)找不到参数的方法android()   根目录下的[build_exkifxt5bplscorlvh4v3btv2 $ _run_closure3 @ 981984c]   project' Recipe App'类型为org.gradle.api.Project。

3 个答案:

答案 0 :(得分:0)

// 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.3.1'

        // 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 25
    buildToolsVersion '25.0.2'
    dexOptions {
        incremental true
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}
dependencies {
    compile files('app/libs/junit-4.12-JavaDoc.jar')
}
apply plugin: 'maven'`enter code here`

答案 1 :(得分:0)

我遇到了同样的问题并解决了问题:

  1. 打开你的'build.gradle'文件,你会发现以下可能是你的comiple版本不同但我想显示文件结构。 android {     compileSdkVersion 25     buildToolsVersion '25 .0.2' } 依赖{ } 发生错误是因为类似的android声明在其他build.gradle文件中。因此删除了android和依赖项。
  2. 了解更多详情here

答案 2 :(得分:0)

添加以下行:

apply plugin: 'com.android.feature'

在有问题的build.gradle文件的顶部并再次同步。