44

我一直在试图将项目导入到Android Studio,这是我卡住的地方,在Stack Overflow上有类似的问题,但它没有提供解决方案,我的特定错误。无法找到方法android()的参数

这是我的错误日志:

C:\<some location>\build.gradle 

Error:(24, 1) A problem occurred evaluating root project '<project name>'. 
> Could not find method android() for arguments [[email protected]] on root project '<project name>'. 
Information:BUILD FAILED 

的摇篮同步消息是:

Error:(24, 0) Gradle DSL method not found: 'android()' Possible causes:

  • The project 'PoojaPeople' 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
  • 我也不太清楚到底在哪这种方法android()所在。如果它位于应用程序的build.gradle文件中,那么我仍然不知道该从哪里下载。任何帮助表示赞赏。

    build.gradle

    buildscript { 
        repositories { 
         maven { url "http://dl.bintray.com/populov/maven" } 
         mavenCentral() 
        } 
        dependencies { 
         classpath 'com.android.tools.build:gradle:2.1.0' 
         // NOTE: Do not place your application dependencies here; they belong 
         // in the individual module build.gradle files 
        } 
    } 
    allprojects { 
        repositories { 
         maven { url "http://dl.bintray.com/populov/maven" } 
         mavenCentral() 
    
        } 
    } 
    task clean(type: Delete) { 
        delete rootProject.buildDir 
    } 
    
    android { 
        compileSdkVersion 17 
        buildToolsVersion '23.0.0' 
    } 
    dependencies { 
        compile files('app/libs/junit-4.12-JavaDoc.jar') 
    } 
    apply plugin: 'maven' 
    
    +1

    你的build.gradle在哪里?发帖 –

    回答

    120

    您使用了错误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' 
    
    +11

    我有同样的问题,你的回答为我解决了它。我在新机器上安装了新版Android Studio,并试图从此回购库安装样本:https://github.com/googlesamples/android-vision我不确定为什么,但在某个时间点导入过程Android Studio自身在顶级build.gradle文件中添加了android()块,该文件不在原始源文件中。 – Karra

    +1

    我有一个旧的Eclipse项目自动导入到AS 2.2.2。它报告的是相同的错误,但在应用程序文件夹内的build.graddle文件中,Gabriele建议移动该android {}部分。所以,这是别的。 – halxinate

    +8

    我真的希望工作室里有更多有意义的信息。我讨厌Eclipse已经停止;工作室在脖子上是如此痛苦。花费更多时间来实际编译代码,而不是实际编写代码。 10倍的时间! –

    1

    guys。当我尝试导入一个.arar包到我的项目中时,我遇到了同样的问题,不幸的是,在将.aar包作为项目的模块依赖项之前,我有两个模块(一个是关于ROS-ANDROID-CV-BRIDGE,one is OPENCV-FOR-ANDROID)已经。所以,我得到这个错误作为你们满足:

    Error:Could not find method android() for arguments [o[email protected]7e550e0e] on project ‘:xxx’ of type org.gradle.api.Project. 
    

    所以,这是痛苦的gradle这个结构导致此问题,当你在你的项目中的多个模块,更糟的是,他们以不同的方式正在导入或有不同的类型(.jar/.aar包或仅仅是Java库的一个项目)。在与主项目兼容的每个子项目中进行像编译版本,库依赖性等配置是一件非常头痛的事情。

    我解决我的问题只是按照此步骤:

    ①在app /库复制.aar包。

    ②在应用程序/文件的build.gradle补充一点:

    repositories { 
        flatDir { 
         dirs 'libs' //this way we can find the .aar file in libs folder 
        } 
    } 
    

    ③要在其中应用.aar依赖(在我的处境中模块的外接的build.gradle文件中添加这,只是在我的应用程序/文件的build.gradle添加此):

    dependencies { 
        compile(name:'package_name', ext:'aar') 
    } 
    

    所以,如果有可能,只是尝试导出模块依赖作为.aar包,然后按照这种方式进口你的主-项目。无论如何,我希望这可以是一个很好的建议,如果你和我有同样的情况,那么这个问题就可以解决你的问题。

    相关问题