无法在Android Studio项目中为参数找到方法android()

Hey*_*yya 11 android build gradle android-studio android-gradle-plugin

我正在尝试在我的android工作室项目上进行成绩同步,并且我在标题中不断收到此错误.我的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.2.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 24
buildToolsVersion '24.0.0'
}
dependencies {

}
Run Code Online (Sandbox Code Playgroud)

我的错误信息是

Gradle sync failed: Could not find method android() for arguments [build_aiwlctiq29euo9devcma4v4r7$_run_closure3@22efc0bc] on root project 'MyRadio
Run Code Online (Sandbox Code Playgroud)

我已经在线查看并尝试了多种解决方案,但似乎没有任何效果.这甚至意味着什么?任何帮助,将不胜感激.

小智 17

您使用的是错误的build.gradle文件.

在顶级文件中,您无法定义android块.

只需将此部分移动到module/build.Gradle文件中即可.

android {
compileSdkVersion 17
buildToolsVersion '23.0.0'
}
dependencies {
compile files('app/libs/junit-4.12-JavaDoc.jar')
}
apply plugin: 'maven'
Run Code Online (Sandbox Code Playgroud)


Aji*_*ian 6

将您的android {}部分移动到此文件 的build.gradle


Rjz*_*ara 5

编辑这个gradle文件 目前您正在编辑顶级 gradle 文件,但您必须编辑应用程序级别

在那里添加依赖项。