无法find方法android()的参数

我一直在试图将项目导入到Android Studio,这是我卡住的地方,有堆栈溢出类似的问题,但它没有提供一个解决我的特定错误。

这是我的错误日志:

C:\<some location>\build.gradle Error:(24, 1) A problem occurred evaluating root project '<project name>'. > Could not find method android() for arguments [build_4fli1jm76ubcnxesnhqnhie47$_run_closure3@6e71db85] on root project '<project name>'. Information:BUILD FAILED 

Gradle同步消息是:

错误:(24,0)未findGradle DSL方法:'android()'可能的原因:

  • 项目“PoojaPeople”可能使用不包含该方法的Gradle版本。 Gradle设置
  • 构build文件可能缺less一个Gradle插件。 应用Gradle插件
  • 我不太确定这个方法android()的位置。 如果它是位于Application的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' 

    您正在使用错误的 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' 

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

     Error:Could not find method android() for arguments [org.ros.gradle_plugins.RosAndroidPlugin$_apply_closure2_closure4@7e550e0e] on project ':xxx' of type org.gradle.api.Project. 

    所以,当你在你的项目中有几个模块,更糟糕的是,它们以不同的方式导入或者有不同的types(.jar / .aar包或者只是一个Java库的项目)时,这就是造成这个问题的痛苦的分级结构。 在与主项目兼容的每个子项目中进行像编译版本,库依赖性等configuration是一件非常头痛的事情。

    我解决了我的问题,只需按照下面的步骤

    ①复制app / libs中的.aar包。

    ②将其添加到app / build.gradle文件中:

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

    ③将这个添加到你想要应用.aar依赖的模块的add build.gradle文件中(在我的情况下,只需将其添加到我的app / build.gradle文件中):

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

    所以,如果可能的话,试试将你的模块依赖导出为一个.aar包,然后按照这种方式将它导入到你的主项目中。 无论如何,我希望这可以是一个很好的build议,并将解决您的问题,如果你有与我一样的情况。