Android Studio 构建失败,并在根项目“MyProject"中找不到“Task". [英] Android Studio build fails with "Task '' not found in root project 'MyProject'."

查看:40
本文介绍了Android Studio 构建失败,并在根项目“MyProject"中找不到“Task".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在更换笔记本电脑并更新到 Android Studio 0.8.2 版后尝试构建我的项目时出现此错误.

I get this error when trying to build my project after changing laptop and updating to Android Studio version 0.8.2.

FAILURE:构建失败,出现异常.

FAILURE: Build failed with an exception.

  • 出了什么问题:在根项目MyProject"中找不到任务".

  • What went wrong: Task '' not found in root project 'MyProject'.

试试:运行 gradle tasks 以获取可用任务的列表.使用 --stacktrace 选项运行以获取堆栈跟踪.使用 --info 或 --debug 选项运行以获得更多日志输出.

Try: Run gradle tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

构建失败

这是我的 Gradle 文件:

Here are my Gradle files:

顶级 settings.gradle

Top Level settings.gradle

include ':MyProject'

MyProject 中的 build.gradle:

build.gradle in MyProject:

apply plugin: 'com.android.application'

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:0.12.+"
    }
}
repositories {
    mavenCentral()
}

android {
    compileSdkVersion 20
    buildToolsVersion "20"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 20
    }
}

dependencies {
    compile 'de.timroes.android:EnhancedListView:0.3.0@aar'
    compile 'com.nineoldandroids:library:2.4.0'
}

顶级 build.gradle 为空

Top level build.gradle is empty

推荐答案

虽然回答晚了,但这对 Google 来说很难(单引号),而且不清楚发生了什么.我还没有评论或要求范围(或发布 3 个链接)的声誉,所以这个答案可能有点乏味.

Though late in answering, this is a hard one to Google (the single quotes) and it’s not clear what’s happening. I don't have the reputation yet to comment or ask for scope (or post 3 links), so this answer may be a little tedious.

为了快速回答,您的项目中可能有多个 Gradle 插件.

To answer fast, you may have multiple Gradle plugins in your project.

我的问题似乎始于损坏的 IML 文件.Android Studio(在关闭和重新打开项目之间)开始抱怨 IML 消失了(它没有)并且应该删除一个模块,我拒绝了.它仍然存在,我升级到 AS 0.8.7(金丝雀频道)并陷入了 OP 问题(在根项目中找不到任务").这完全阻止了构建,所以我不得不深入研究 Gradle.

My issue seemed to start with a corrupted IML file. Android Studio (between closing and reopening a project) began complaining an IML was gone (it wasn’t) and a module should be deleted, which I declined. It persisted, I upgraded to AS 0.8.7 (canary channel) and got stuck on the OP issue (Task '' not found in root project). This completely blocked builds so I had to dig in to Gradle.

我在 OSX 上的修复步骤(请针对 Windows 进行调整):

My repair steps on OSX (please adjust for Windows):

  1. 将 Android Studio 升级到 0.8.7
    • 首选项 |更新 |将Beta 版频道"切换为Canary 频道",然后立即检查.
    • 你可以跳过这个.

检查 Gradle 包装器(当前为 1.12.2;此时不要尝试使用 2.0).

Checked the Gradle wrapper (currently 1.12.2; don’t try to use 2.0 at this time).

$ vi ~/project/gradle-wrapper.properties...distributionUrl=http\://services.gradle.org/distributions/gradle-1.12-all.zip

这可以在 Android Studio 的 Preferences | 中设置Gradle(但 0.8.7 给了我无效位置"错误).

This can be set in Android Studio at Preferences | Gradle (but 0.8.7 was giving me ‘invalid location’ errors).

例如,在 build.gradle 中,你有这个插件:

Example, in build.gradle, you have this plugin:

dependencies {
    classpath "com.android.tools.build:gradle:0.12.+"
}

您可以尝试将其切换到确切版本,如下所示:

You can try switching it to the exact version, like this:

dependencies {
    classpath "com.android.tools.build:gradle:0.12.2"
}

并且(在记录您在每种情况下更改的版本之后)验证项目中的每个 build.gradle 文件都拉入相同的插件版本.保留+"应该可以工作(对于 0.12.0、0.12.1、0.12.2 等),但是当我更新 Google 的 Volley 库(最初 gradle:0.8.+)和我的主要项目(最初为 0.12.2.1)时,我的构建成功了.+) 到固定版本:gradle:0.12.2.

and (after recording what version you’re changing from in each case) verifying that every build.gradle file in your project pulls in the same plugin version. Keeping the "+" should work (for 0.12.0, 0.12.1, 0.12.2, etc), but my build succeeded when I updated Google’s Volley library (originally gradle:0.8.+) and my main project (originally 0.12.+) to the fixed version: gradle:0.12.2.

  1. 确保在同一个项目中没有两个 Android 应用程序模块

  1. Ensure you don’t have two Android Application modules in the same Project

  • 这可能与最终解决方案(不同的 Gradle 版本,以上)相互作用,并导致

  • This may interact with the final solution (different Gradle versions, above), and cause

意外的顶级异常:com.android.dex.DexException:多个 dex 文件定义(各种类)

要检查,构建 |Make Project 不应弹出询问您要制作什么应用程序的窗口.

To check, Build | Make Project should not pop up a window asking what application you want to make.

  • 文件 |使缓存无效/重新启动 (stackoverflow.com/a/19223269/513413)
  • 退出 Android Studio
  • $ rm -rf ~/.gradle/
  • 启动 Android Studio,然后同步:
    • 工具|安卓 |将项目与 Gradle 文件同步
    • 构建 |清洁项目

    如果你看到这个...

    在我最近的构建中,我不断看到可怕的失败(异常页面),但在几秒钟内消息就会清除,构建成功并部署了应用程序.由于我永远无法解释它并且该应用程序可以运行,因此我从未注意到我的项目中有两个 Gradle 插件.所以我认为 Gradle 插件互相争斗;一个崩溃了,另一个失去了状态并报告了错误.

    If You See This...

    In my recent builds, I kept seeing horrible fails (pages of exceptions) but within seconds the messages would clear, build succeeded and the app deployed. Since I could never explain it and the app worked, I never noticed that I had two Gradle plugins in my project. So I think the Gradle plugins fought each other; one crashed, the other lost its state and reported the error.

    如果您有时间,1 小时的视频Gradle 简介"(www.youtube.com/watch?v=OFUEb7pLLXw) 确实帮助我了解了 Gradle 构建文件、任务、构建决策等.

    If you have time, the 1-hour video "A Gentle Introduction to Gradle" (www.youtube.com/watch?v=OFUEb7pLLXw) really helped me approach the Gradle build files, tasks, build decisions, etc.

    在从事不同的职业之后,我正在外国操作系统上学习整个堆栈……所有这些都是在压力下同时进行的.在过去的几个月里,我遇到了我认为 Android 遇到的每一面墙;我经常来这里,这是我的第一篇文章.我认为这是一个很难解决的问题,所以如果我的回答的质量反映了我在解决它时遇到的困难,我真诚地道歉.

    I'm learning this entire stack, on a foreign OS, after working a different career...all at the same time and under pressure. In the last few months I have hit every wall I think Android has; I've been here quite often and this is my first post. I thought this was a hard fix, so I sincerely apologize if the quality of my answer reflects the difficulty I had in getting to it.

    这篇关于Android Studio 构建失败,并在根项目“MyProject"中找不到“Task".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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