找不到Gradle DSL方法:android() [英] Gradle DSL method not found: android()

查看:229
本文介绍了找不到Gradle DSL方法:android()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何解决此问题的建议: 导入Project后,我在android studio中收到此错误

Any suggestions to fix this problem: I am getting this error in android studio after importing Project

错误:(16,0)未找到Gradle DSL方法:"android()" 可能的原因:

  • 项目'LoginActivity'可能正在使用不包含该方法的Gradle版本. Gradle设置
  • 构建文件可能缺少Gradle插件. 应用Gradle插件
  • Error:(16, 0) Gradle DSL method not found: 'android()' Possible causes:

  • The project 'LoginActivity' may be using a version of Gradle that does not contain the method. Gradle settings
  • The build file may be missing a Gradle plugin. Apply Gradle plugin
  • // 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:1.1.0'
        }
    }
    allprojects {
        repositories {
            jcenter()
        }
    }
    
    android {
        compileSdkVersion 21
        buildToolsVersion '21.0.0'
        dexOptions {
            incremental true
        }
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_6
            targetCompatibility JavaVersion.VERSION_1_6
        }
    }
    dependencies {
        compile 'com.android.support:support-v4:21.0.3'
        compile 'com.android.support:appcompat-v7:21.0.3'
    }
    apply plugin: 'eclipse'
    apply plugin: 'java'
    

    有一条条形通知:Gradle项目同步失败.基本功能(例如,编辑,调试)将无法正常工作.

    There is a bar notification which says: Gradle project sync failed. Basic fuctionality (eg: editing, debugging) will not work properly.

    请帮助我摆脱这个问题.谢谢!

    Please help me to get rid of this problem. Thanks!

    推荐答案

    如果构建脚本中包含android块,则需要以下两个语句之一,具体取决于您的模块是应用程序模块还是应用程序模块.库模块:

    If you have an android block in your build script, you need one of the following two statements, depending on whether your module is an application module or a library module:

    apply plugin: 'com.android.application'
    

    或:

    apply plugin: 'com.android.library'
    

    话虽如此,您的构建脚本还有其他问题.例如,这是一个顶层构建脚本(如注释中所示的可以在其中添加配置选项的顶层构建文件..."所示),因此实际上可能没有顶层脚本级别模块适用于android块,因此添加apply plugin语句可能只会导致其他错误.如果发生这种情况,请删除android块.

    Having said that, there are other problems with your build script. For one, this is a top-level build script (as you can see by the comment that says "Top-level build file where you can add configuration options..."), so it's likely that there isn't actually a top-level module for the android block to apply to, so adding the apply plugin statement may just lead to a different error. If that happens, remove the android block.

    另一个问题是此构建脚本中已经有一个apply plugin: 'java'语句.您不能在同一构建脚本中同时使用Java和Android插件.他们彼此碰撞.

    Another issue is that you already have a apply plugin: 'java' statement in this build script. You can't use both the Java and the Android plugins in the same build script; they collide with each other.

    这篇关于找不到Gradle DSL方法:android()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆