java Android Studio 错误:错误:(23, 0) 找不到根项目参数的方法 android()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39046363/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 04:02:24  来源:igfitidea点击:

Android studio error:Error:(23, 0) Could not find method android() for arguments on root project

javaandroidandroid-studioandroid-gradle-pluginbuild.gradle

提问by Ori V Agmon

I reinstalled android studio, I am using the same project with android studio in another PC so the code is probably fine! It is the full error:

我重新安装了 android studio,我在另一台 PC 上使用了与 android studio 相同的项目,所以代码可能没问题!这是完整的错误:

 Error:(23, 0) Could not find method android() for arguments [build_1z9k6ruj47plglocgqknjnoag$_run_closure3@133cf914] on root project 'allthingsvegan-android-9d296805dc64' of type org.gradle.api.Project.

Open File

打开文件



The solutions I've found on the internet was including changing the code.. So they are not relevant to me

我在互联网上找到的解决方案包括更改代码..所以它们与我无关

Thanks!! build.gradle:

谢谢!!构建.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.0-beta1'
        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 {
    buildToolsVersion '24.0.1'
}

回答by Gabriele Mariotti

It is the top-level build.gradlefile.
In this file you can't use this block:

它是顶级build.gradle文件。
在这个文件中你不能使用这个块:

android {
    buildToolsVersion '24.0.1'
}

Remove this block.

删除此块。

回答by ligi

you need to apply the android plugin:

你需要应用android插件:

 apply plugin: 'com.android.application'

this needs to be done after buildscript like this:

这需要在像这样的构建脚本之后完成:

// 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-beta1'
        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
}

apply plugin: 'com.android.application'

android {
    buildToolsVersion '24.0.1'
}

回答by Navin a.s

  • uncomment android tag present in build.gradle(Project:android-start)enter image description here
  • rebuild the gradle it asks to update .
  • Update the gradle then sync it works
  • 取消注释build.gradle 中存在的 android 标记(项目:android-start)在此处输入图片说明
  • 重建它要求更新的gradle。
  • 更新gradle然后同步它的工作原理