【问题标题】:Android studio error:Error:(23, 0) Could not find method android() for arguments on root projectAndroid Studio 错误:Error:(23, 0) 找不到方法 android() 用于根项目的参数
【发布时间】:2016-12-27 01:07:39
【问题描述】:

我重新安装了 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.

打开文件


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

谢谢!! 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.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'
}

【问题讨论】:

  • 尝试清理项目
  • 显示你的 build.gradle
  • 我已经用 build.gradle 编辑了原帖
  • 尝试清理项目没有成功(与此处提到的问题相同)
  • @ligi 忘了通知你

标签: java android android-studio android-gradle-plugin build.gradle


【解决方案1】:

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

android {
    buildToolsVersion '24.0.1'
}

删除此块。

【讨论】:

    【解决方案2】:

    你需要应用android插件:

     apply plugin: 'com.android.application'
    

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

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

    【讨论】:

    • 我是 android studio 的新手。构建脚本是什么意思?我需要在哪里写? @ligi
    • 谢谢改了,现在报错:compile sdk version is not specified @ligi
    • 您的项目中有 2 个 build.gradle 文件吗?
    • 是的,我想是的,一个在 gradle 文件夹下,一个在 gradle 脚本下@ligi
    【解决方案3】:
    • 取消注释 build.gradle(Project:android-start) 中存在的 android 标记
    • 重建它要求更新的 gradle。
    • 更新 gradle 然后同步它的工作原理

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-22
      • 2015-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多