在 Android Studio 项目中找不到参数的方法 android()
Posted
技术标签:
【中文标题】在 Android Studio 项目中找不到参数的方法 android()【英文标题】:Could not find method android() for arguments in Android Studio project 【发布时间】:2017-02-22 02:20:24 【问题描述】:我正在尝试对我的 android studio 项目进行成绩同步,但标题中不断出现此错误。我的 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
我的错误信息是
Gradle sync failed: Could not find method android() for arguments [build_aiwlctiq29euo9devcma4v4r7$_run_closure3@22efc0bc] on root project 'MyRadio
我在网上查看并尝试了多种解决方案,但似乎没有任何效果。这甚至意味着什么?任何帮助将不胜感激。
【问题讨论】:
其实你正在编辑错误的gradle文件。 把你的 android 和依赖项放到 app 文件夹中的 build.gradle 中。不在根项目文件夹中。 【参考方案1】:您使用了错误的 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'
【讨论】:
【参考方案2】:将您的 android 部分移动到此文件
【讨论】:
【参考方案3】:目前您正在编辑*** gradle 文件,但您必须编辑 App 级别
在那里添加依赖项。
【讨论】:
【参考方案4】:每个模块添加到您的 Android Studio 项目 has its own build.gradle
文件中。您要添加的任何依赖项都将添加到关联的模块 build.gradle 文件中。
因此,在您的情况下,您必须在应用的 build.gradle 文件中添加依赖项。
这是一张图片,显示您应该在哪里添加它。
【讨论】:
【参考方案5】:删除以下内容后刷新gradle
android
compileSdkVersion 24
buildToolsVersion '24.0.0'
dependencies
对我有用
【讨论】:
奇怪的解决方案!但它也对我有用......谢谢你:-)【参考方案6】:检查您的APP级别Build.Gradle
是否缺少Plugin
然后添加apply plugin: 'com.android.application'
在APP级Build.Gradle
来自我的解决方案。
【讨论】:
以上是关于在 Android Studio 项目中找不到参数的方法 android()的主要内容,如果未能解决你的问题,请参考以下文章
Android Studio 构建失败,“在根项目‘MyProject’中找不到任务’。”
在根项目中找不到 Android Studio 0.8 任务组合
在 android studio 中找不到 proguard-project.txt
为啥在 Visual Studio 2019 (XAMARIN) 中找不到 Android 库