缺少Android的工作室主模块 [英] Missing main module in Android studio

查看:172
本文介绍了缺少Android的工作室主模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我从日食Android应用移植到Android的工作室。 (0.5.4)
该项目有几个依赖关系。 (夏洛克等)
我导出应用摇篮和进口它的Andr​​oid工作室,并设法让该项目成功打造。

看来然而,只有依赖关系构建。
在应用程序code添加erronous线不会触发编译错误。

当我查看项目|包时,包我的应用程序不显示,只有外部库所示。

我的根级别的build.gradle只包含库和依赖关系:

  buildscript {
    库{
        mavenCentral()
    }    依赖{
        类路径'com.android.tools.build:gradle:0.9.2
    }

我手动尝试添加一个机器人部分的意图,使gradle这个看源代码文件,但我不得不添加的部分问题:

  buildscript {
    库{
        mavenCentral()
    }    依赖{
        类路径'com.android.tools.build:gradle:0.9.2
    }
    安卓{
        compileSdkVersion 17
        buildToolsVersion19.0.2
    }

就像我现在得到以下错误


  

找不到根工程ZZZ的论点XXX法的Andr​​oid()。


如果继续添加

 应用插件:'机器人'

就在Android的部分,但现在我得到


  

时出现问题评估根项目ZZZ。
  插件ID为'机器人'未找到。


任何人都可以提供一些线索,为什么我不能在根级别一个Android部分。
如果问题出在其他地方的任何帮助,也将是多少AP preciated。

在情况下,它是需要的,这里是我的settings.gradle

 包括':外用:PullToRefresh:SmoothProgressBarLib
包括:外用:ActionBarSherlock
包括':'
包括:外用:pulltorefresh-ABS
包括:外用:MyAwesomeLibrary
包括:外用:PullToRefresh:pulltorefresh
包括:外用:SherlockNavigationDrawer
包括:外用:SDK:MyAwesomeSDK


解决方案

您已经包含内部的机器人块中的 buildscript 在顶层构建文件块,但这是不正确。相反,它的结构应是这样的:

  buildscript {
    库{
        mavenCentral()
    }    依赖{
        类路径'com.android.tools.build:gradle:0.9.2
    }
}应用插件:'机器人'库{
    mavenCentral()
}安卓{
    compileSdkVersion 17
    buildToolsVersion19.0.2
}依赖{
    //你的应用程序依赖去这里
}

这一切都是假设你真正拥有一个Android应用程序模块在项目的根(这意味着你的项目根目录下有一个的src 的目录中有Android的来源吧)。这似乎是你试图将其设置这种方式,因为你也有这样的在你的settings.gradle文件:

 包括':'

如果是这样的话,那么重新安排你的顶层构建文件如上所示应该修复它。

如果你没有在项目根模块,那么你应该顶层构建文件恢复到原来的状态(取出应用插件和<从<线b> settings.gradle ,并添加:code>机器人),取出了包括''一个包含语句指向你的应用模块。

I am trying to migrate my android app from eclipse to Android studio. (0.5.4) The project has several dependencies. (Sherlock etc) I exported the app to Gradle and imported it in Android studio and managed to get the project to build successfully.

It appears however that only the dependencies are built. Adding erronous lines in the app code does not trigger compile errors.

When I view project | packages, the package for my app does not show, Only the external libraries are shown.

My root level build.gradle only contains repositories and dependencies:

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:0.9.2'
    }

I tried manually adding an android section with the intent to make gradle look at the source files but I had problems adding the section:

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:0.9.2'
    }
    android {
        compileSdkVersion 17
        buildToolsVersion "19.0.2"
    }

As i now get the following error

Could not find method android() for arguments xxx on root project 'zzz'.

If proceeded to add

apply plugin: 'android'

Just before the android section, but now I get

A problem occurred evaluating root project 'zzz'. Plugin with id 'android' not found.

Can anyone shed some light as to why i cannot have an Android section at the root level. If the problem lies somewhere else any help would also be much appreciated.

In case it is needed, here is my settings.gradle

include ':external:PullToRefresh:SmoothProgressBarLib'
include ':external:ActionBarSherlock'
include ':'
include ':external:pulltorefresh-abs'
include ':external:MyAwesomeLibrary'
include ':external:PullToRefresh:pulltorefresh'
include ':external:SherlockNavigationDrawer'
include ':external:sdk:MyAwesomeSDK'

解决方案

You've included an android block inside a buildscript block in your top-level build file, but this is incorrect. Instead it should be structured like this:

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:0.9.2'
    }
}

apply plugin: 'android'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 17
    buildToolsVersion "19.0.2"
}

dependencies {
    //Your app dependencies go here
}

All this is assuming that you truly have an Android application module at your project root (meaning that at your project root directory there's a src directory that has Android sources in it). It seems to be that you're trying to set it up this way because you also have this in your settings.gradle file:

include ':'

If that's the case, then rearranging your top-level build file as indicated above should fix it.

If you don't have a module at the project root, then you should restore the top-level build file to its original condition (take out apply plugin and android), take out that include ':' line from settings.gradle, and add an include statement that points to your application module.

这篇关于缺少Android的工作室主模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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