Android Studio build在根项目“MyProject”中没有找到“Task”时失败。

时间:2021-11-16 17:03:54

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

我在更改笔记本并更新到Android Studio 0.8.2版本后尝试构建我的项目时遇到了这个错误。

FAILURE: Build failed with an exception.

失败:构建失败,但有一个例外。

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

    出错的地方:任务“没有在根项目‘MyProject’中找到。

  • 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.

    尝试:运行渐变任务来获取可用任务列表。使用—stacktrace选项运行,以获取堆栈跟踪。使用-info或-debug选项运行,以获得更多日志输出。

BUILD FAILED

构建失败

Here are my Gradle files:

这是我的Gradle文件:

Top Level settings.gradle

*settings.gradle

include ':MyProject'

build.gradle in MyProject:

构建。gradle 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'
}

Top level build.gradle is empty

*的构建。它是空的

17 个解决方案

#1


58  

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.

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

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

要快速回答,您的项目中可能有多个级别的插件。

Synchronize Gradle Wrapper and Plugins

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.

我的问题似乎是从一个损坏的IML文件开始的。Android Studio(在关闭和重新打开一个项目之间)开始抱怨IML没有了(它没有),一个模块应该被删除,我拒绝了。它持续存在,我升级为0.8.7 (canary channel),并陷入OP问题(任务“在root项目中没有发现)。这完全阻塞了构建,所以我不得不深入到Gradle。

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

我在OSX上的维修步骤(请根据窗户进行调整):

  1. Upgrade Android Studio to 0.8.7
    • Preferences | Updates | Switch "Beta Channel" to "Canary Channel", then do a Check Now.
    • |更新|“Beta频道”到“Canary频道”,然后现在进行检查。
    • You might be able to skip this.
    • 你可以跳过这个。
  2. 升级Android Studio到0.8.7 Preferences |更新|将“Beta频道”切换到“Canary频道”,现在进行检查。你可以跳过这个。
  3. Checked the Gradle wrapper (currently 1.12.2; don’t try to use 2.0 at this time).

    检查等级包装(目前为1.12.2;现在不要尝试使用2.0)。

    • Assuming you don’t need a particular version, use the latest supported distribution

      假设您不需要特定的版本,请使用最新支持的发行版

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

      vi ~ /项目/ gradle-wrapper美元。属性……distributionUrl = http \:/ /services.gradle.org/distributions/gradle all.zip——1.12

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

      这可以在Android Studio中设置为Preferences | Gradle(但是0.8.7会给我带来“无效位置”错误)。

    • The 'wrapper' is just a copy of Gradle for each Android Studio project. It allows you to have Gradle 2 in your OS, and different versions in your projects. The Android Developer docs explain that here.
    • “包装器”只是每个Android Studio项目的Gradle的副本。它允许您在操作系统中使用第二级,在项目中使用不同的版本。Android开发者文档在这里解释了这一点。
    • Then adjust your build.gradle files for the plugin. The Gradle plugin version must be compatible with the distribution/wrapper version, for the whole project. As the Tools documentation (tools.android.com/tech-docs/new-build-system/user-guide#TOC-Requirements) is slightly out of date, you can set the plugin version too low (like 0.8.0) and Android Studio will throw an error with the acceptable range for the wrapper.
    • 然后调整您的构建。插件的渐变文件。对于整个项目来说,Gradle插件版本必须与发行版/包装版兼容。由于工具文档(Tools .android.com/tech-docs/new build-system/user-guide#TOC-Requirements)有些过时,您可以将插件版本设置得太低(比如0.8.0),而Android Studio将抛出一个错误,导致包装器的可接受范围。

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"
}

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.

并且(在记录了您从每个案例中更改了什么版本之后)来验证每个构建。项目中的gradle文件会引入相同的插件版本。保持“+”应该可以工作(0.12.0、0.12.1、0.12.2等等),但是当我更新谷歌的Volley库(最初的等级是0.8.+)和主项目(最初的等级是0.12.+)到固定版本时,我的构建成功了:0.12.2。

Other checks

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

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

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

      这可能与最终的解决方案(上面不同的等级版本)和原因交互

      UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple dex files define (various classes)

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

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

      要检查,构建| Make项目不应该弹出一个窗口询问您想要创建的应用程序。

  2. Invalidate your caches
    • File | Invalidate Caches / Restart (*.com/a/19223269/513413)
    • 文件|无效/重启缓存(*.com/a/19223269/513413)
  3. 使你的缓存文件|失效/重新启动(*.com/a/19223269/513413)
  4. If step 2 doesn't work, delete ~/.gradle/ (www.wuttech.com/index.php/tag/groovy-lang-closure/)
    • Quit Android Studio
    • 退出Android工作室
    • $ rm -rf ~/.gradle/
    • rm射频~ / .gradle /美元
    • Start Android Studio, then sync:
      • Tools | Android | Sync Project with Gradle Files
      • 工具| Android |同步项目与等级文件
    • 启动Android Studio,然后同步:工具| Android |同步项目,带有等级文件
    • Repeat this entire sequence (quit...sync) a few times before giving up.
    • 在放弃之前,重复这整个过程(退出,同步)几次。
  5. 如果步骤2不起作用,删除~/。gradle/ (www.wuttech.com/index.php/tag/groovy-lang-closure/)退出Android Studio $ rm -rf ~/。逐步/启动Android Studio,然后同步:工具| Android |同步项目,使用等级文件重复整个序列(退出…同步)几次,然后放弃。
  6. Clean the project
    • Build | Clean Project
    • 构建|清洁项目
  7. 清洁项目建设|清洁项目

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.

在我最近的构建中,我一直看到可怕的失败(异常页面),但在几秒钟内,消息就会清晰,构建成功,应用程序部署完毕。因为我无法解释它,而且这个应用程序也能工作,所以我从来没有注意到我的项目中有两个等级的插件。所以我认为这些插件互相竞争;一个崩溃了,另一个失去了状态并报告了错误。

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.

如果你有时间的话,1小时的视频《轻松入门》(www.youtube.com/watch?

Disclaimer

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的每一道墙都被我击中了;我经常来这里,这是我的第一个帖子。我认为这是一个艰难的解决办法,所以我真诚地道歉,如果我的回答质量反映了我在这方面遇到的困难。

#2


22  

Download system image(of targeted android level of your project) from sdk manager for the project you have imported.

为导入的项目从sdk管理器下载系统镜像(项目的目标android级别)。

This error comes when you do not have target sdk of your android project installed in sdk folder

当在sdk文件夹中没有安装android项目的目标sdk时,就会出现此错误

for eg. Your imported project's target sdk level may be android-19 and on sdk folder->system-images you may have android-21 installed. so you have to download android-19 system image and other files from sdk manager or you can copy paste it if you have the system image.

如。您导入的项目的目标sdk级别可能是android-19,在sdk文件夹——>系统镜像中,您可能已经安装了android-21。所以你必须从sdk管理器下载android-19系统镜像和其他文件,如果你有系统镜像,你也可以复制粘贴。

#3


13  

Remove:

删除:

<facet type="android" name="Android">
    <configuration />
</facet>

in your iml file. That works for me.

安恩科技文件中。这适合我。

https://plus.google.com/+AlexRuiz/posts/49hP3V9GSGe

https://plus.google.com/ + AlexRuiz /文章/ 49 hp3v9gsge

#4


9  

This happened to me recently when I close one Android Studio project and imported another Eclipse project. It seemed to be some bug in Android Studio where it preserves some gradle settings from previously open project and then get confused in the new project.

最近,当我关闭一个Android Studio项目并导入另一个Eclipse项目时,我就遇到了这种情况。这似乎是Android Studio中的一个bug,它保留了以前开放项目中的一些等级设置,然后在新项目中出现了混乱。

The solution was extremely simple: Close the project and shut down Android Studio completely, before re-opening it and then import/open the new project. Everything goes smoothly from then on.

解决方案非常简单:关闭项目并完全关闭Android Studio,然后重新打开它,然后导入/打开新项目。从那时起一切都很顺利。

#5


4  

Simple fix for me was

对我来说,简单的解决办法是

  1. Build > Clean project
  2. 构建>清洁项目
  3. Restart Android Studio
  4. 重新启动Android工作室

#6


3  

Apparently this error has multiple causes. Here's what fixed it for me.

显然,这个错误有多种原因。这是我修复它的方法。

I was running the build command like this:

我运行的构建命令如下:

./gradlew :testapp: build

Running it without the space fixed the issue:

在没有空格的情况下运行,解决了问题:

./gradlew :testapp:build

#7


2  

In my case, setting the 'Gradle version' same as the 'Android Plugin version' under File->Project Structure->Project fixed the issue for me.

在我的例子中,>项目结构下的“Gradle version”与“Android Plugin version”相同,>项目为我解决了这个问题。

#8


2  

Sometimes, if you have opened two windows of Android Studio, and when you try to compile, this issue might happen. For me, when I was compiling a backed Google Cloud Endpoint module which was not embedded in a project, rather shared among different Android Studio projects, and when there is more than once instance open, this error use to spring up for me. But as soon as you close other windows, everything will be fine. Sometimes, you might have to restart Android Studio altogether.

有时,如果您打开了Android Studio的两个窗口,当您尝试编译时,这个问题可能会发生。对我来说,当我编译一个备份的谷歌云端点模块时,它没有嵌入到一个项目中,而是在不同的Android Studio项目*享,当有多个实例打开时,这个错误就会出现。但只要你关上其他窗口,一切都会好起来的。有时,你可能不得不重新启动Android Studio。

#9


1  

Make sure you have the latest values in your gradle files. As of this writing:

确保您的等级文件中有最新的值。在撰写本文时:

  • buildToolsVersion "21.1.2"

    buildToolsVersion“21.1.2”

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

    依赖项{类路径'com.android.tools.build:gradle:1.1.0'}

#10


1  

Yet another solution to the same problem:

同样问题的另一个解决办法是:

This happened to me every time I imported an eclipse project into studio using the wizard (studio version 1.3.2).

每次我使用向导(studio version 1.3.2)将eclipse项目导入studio时,就会发生这种情况。

What I found, quite by chance, was that quitting out of Android studio and then restarting studio again made the problem go away.

我很偶然地发现,退出Android studio,然后重新启动studio,这个问题就解决了。

Frustrating, but hope this helps someone...

令人沮丧,但希望这能帮助某人…

#11


1  

I got this error when switching from one Git branch to another, and then trying to run "Clean Project". I used ack to search for the Task name, and found it in a .iml file.

在从一个Git分支切换到另一个Git分支时,我得到了这个错误,然后尝试运行“Clean Project”。我使用ack搜索任务名,并在一个.iml文件中找到它。

My solution was to regenerate the project's .iml file by clicking (in the main menu) Tools > Android > Sync Project with Gradle Files. (Thanks to this answer.)

我的解决方案是通过点击(在主菜单中)工具> Android > Sync项目来重新生成项目的.iml文件。(由于这答案。)

#12


0  

Set the path of the root folder and after run the below command

设置根文件夹的路径,并运行以下命令。

ex : cd C:\Users\maha\Documents\gradle\gs-gradle-master\initial

#13


0  

This is what I did

这就是我所做的

  1. Remove .idea folder

    删除.idea文件夹

    $ mv .idea .idea.bak

    美元mv .idea .idea.bak

  2. Import the project again

    再次导入项目

#14


0  

I remove/Rename .gradle folder in c:\users\Myuser\.gradle and restart Android Studio and worked for me

我删除/重命名.gradle文件夹在c:\用户\Myuser\ \ \。葛拉德和重启Android Studio,并为我工作

#15


0  

  1. Open Command Prompt
  2. 打开命令提示符
  3. then go your project folder thru Command prompt
  4. 然后通过命令提示符进入项目文件夹
  5. Type gradlew build and run
  6. 类型级配流构建和运行。

#16


0  

Apparently this issue caused by Android Studio on the various situation but the reason is build error When importing an existing project into android studio.

In my case, I've imported my exist project where I was supposed to install few build tools then finally build configuration was done with error. In this case, just do the following things

显然这个问题是由Android Studio在各种情况下引起的,但是原因是在将一个现有项目导入Android Studio时出现了构建错误。在我的例子中,我导入了我的exist项目,在那里我应该安装很少的构建工具,然后最终构建配置是错误的。在这种情况下,只需做以下事情

  1. Close the current project
  2. 关闭当前项目
  3. File>New>Import Project (Don't use the open recent project)

    Note: I'm sure this kind of error is not on source code when this happened on Import project.
  4. 文件>新的>导入项目(不要使用最近的开放项目)注意:我确信当导入项目发生这种情况时,这种错误不在源代码中。

#17


0  

Problem

I specifically got the "[module_name]:prepareDebugUnitTestDependencies" task not found error, every time I ran gradle build. This happened to me after updating my Android Studio to 3.0.0.

我特别得到了“[module_name]:prepareDebugUnitTestDependencies”任务没有发现错误,每次我运行gradle构建。这发生在我将Android Studio更新为3.0.0之后。

Investigation

I had previously added command-line options to the gradle-based compiler, which you can find under: File -> Settings -> Build, Execution, Deployment -> Compiler -> Command-line Options. Specifically, I had excluded a number of tasks, including the aforementioned task. While that worked fine on the previous stable version (2.3 at that time), it seems like this was the reason behind the build failure.

我之前已经向基于级别的编译器添加了命令行选项,您可以在下面找到:File—>设置—>构建、执行、部署—>编译器—>命令行选项。具体地说,我排除了一些任务,包括前面提到的任务。虽然在以前的稳定版本(当时是2.3)上运行良好,但这似乎是导致构建失败的原因。

Solution

This is one of many possible solutions. Make sure you have the correct command-line options specified in the settings under: File -> Settings -> Build, Execution, Deployment -> Compiler -> Command-line Options, and that none of them is causing this problem.

这是许多可能的解决方案之一。请确保在以下设置中指定了正确的命令行选项:File ->设置->构建、执行、部署->编译器->命令行选项,并且它们都不会导致这个问题。

In my case, I removed the exclusion of this task (and other tasks that seemed related), left the unrelated tasks excluded, and it worked!

在我的例子中,我删除了这个任务(以及其他看起来相关的任务)的排除,将不相关的任务排除在外,并且它工作了!

#1


58  

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.

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

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

要快速回答,您的项目中可能有多个级别的插件。

Synchronize Gradle Wrapper and Plugins

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.

我的问题似乎是从一个损坏的IML文件开始的。Android Studio(在关闭和重新打开一个项目之间)开始抱怨IML没有了(它没有),一个模块应该被删除,我拒绝了。它持续存在,我升级为0.8.7 (canary channel),并陷入OP问题(任务“在root项目中没有发现)。这完全阻塞了构建,所以我不得不深入到Gradle。

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

我在OSX上的维修步骤(请根据窗户进行调整):

  1. Upgrade Android Studio to 0.8.7
    • Preferences | Updates | Switch "Beta Channel" to "Canary Channel", then do a Check Now.
    • |更新|“Beta频道”到“Canary频道”,然后现在进行检查。
    • You might be able to skip this.
    • 你可以跳过这个。
  2. 升级Android Studio到0.8.7 Preferences |更新|将“Beta频道”切换到“Canary频道”,现在进行检查。你可以跳过这个。
  3. Checked the Gradle wrapper (currently 1.12.2; don’t try to use 2.0 at this time).

    检查等级包装(目前为1.12.2;现在不要尝试使用2.0)。

    • Assuming you don’t need a particular version, use the latest supported distribution

      假设您不需要特定的版本,请使用最新支持的发行版

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

      vi ~ /项目/ gradle-wrapper美元。属性……distributionUrl = http \:/ /services.gradle.org/distributions/gradle all.zip——1.12

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

      这可以在Android Studio中设置为Preferences | Gradle(但是0.8.7会给我带来“无效位置”错误)。

    • The 'wrapper' is just a copy of Gradle for each Android Studio project. It allows you to have Gradle 2 in your OS, and different versions in your projects. The Android Developer docs explain that here.
    • “包装器”只是每个Android Studio项目的Gradle的副本。它允许您在操作系统中使用第二级,在项目中使用不同的版本。Android开发者文档在这里解释了这一点。
    • Then adjust your build.gradle files for the plugin. The Gradle plugin version must be compatible with the distribution/wrapper version, for the whole project. As the Tools documentation (tools.android.com/tech-docs/new-build-system/user-guide#TOC-Requirements) is slightly out of date, you can set the plugin version too low (like 0.8.0) and Android Studio will throw an error with the acceptable range for the wrapper.
    • 然后调整您的构建。插件的渐变文件。对于整个项目来说,Gradle插件版本必须与发行版/包装版兼容。由于工具文档(Tools .android.com/tech-docs/new build-system/user-guide#TOC-Requirements)有些过时,您可以将插件版本设置得太低(比如0.8.0),而Android Studio将抛出一个错误,导致包装器的可接受范围。

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"
}

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.

并且(在记录了您从每个案例中更改了什么版本之后)来验证每个构建。项目中的gradle文件会引入相同的插件版本。保持“+”应该可以工作(0.12.0、0.12.1、0.12.2等等),但是当我更新谷歌的Volley库(最初的等级是0.8.+)和主项目(最初的等级是0.12.+)到固定版本时,我的构建成功了:0.12.2。

Other checks

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

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

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

      这可能与最终的解决方案(上面不同的等级版本)和原因交互

      UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple dex files define (various classes)

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

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

      要检查,构建| Make项目不应该弹出一个窗口询问您想要创建的应用程序。

  2. Invalidate your caches
    • File | Invalidate Caches / Restart (*.com/a/19223269/513413)
    • 文件|无效/重启缓存(*.com/a/19223269/513413)
  3. 使你的缓存文件|失效/重新启动(*.com/a/19223269/513413)
  4. If step 2 doesn't work, delete ~/.gradle/ (www.wuttech.com/index.php/tag/groovy-lang-closure/)
    • Quit Android Studio
    • 退出Android工作室
    • $ rm -rf ~/.gradle/
    • rm射频~ / .gradle /美元
    • Start Android Studio, then sync:
      • Tools | Android | Sync Project with Gradle Files
      • 工具| Android |同步项目与等级文件
    • 启动Android Studio,然后同步:工具| Android |同步项目,带有等级文件
    • Repeat this entire sequence (quit...sync) a few times before giving up.
    • 在放弃之前,重复这整个过程(退出,同步)几次。
  5. 如果步骤2不起作用,删除~/。gradle/ (www.wuttech.com/index.php/tag/groovy-lang-closure/)退出Android Studio $ rm -rf ~/。逐步/启动Android Studio,然后同步:工具| Android |同步项目,使用等级文件重复整个序列(退出…同步)几次,然后放弃。
  6. Clean the project
    • Build | Clean Project
    • 构建|清洁项目
  7. 清洁项目建设|清洁项目

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.

在我最近的构建中,我一直看到可怕的失败(异常页面),但在几秒钟内,消息就会清晰,构建成功,应用程序部署完毕。因为我无法解释它,而且这个应用程序也能工作,所以我从来没有注意到我的项目中有两个等级的插件。所以我认为这些插件互相竞争;一个崩溃了,另一个失去了状态并报告了错误。

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.

如果你有时间的话,1小时的视频《轻松入门》(www.youtube.com/watch?

Disclaimer

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的每一道墙都被我击中了;我经常来这里,这是我的第一个帖子。我认为这是一个艰难的解决办法,所以我真诚地道歉,如果我的回答质量反映了我在这方面遇到的困难。

#2


22  

Download system image(of targeted android level of your project) from sdk manager for the project you have imported.

为导入的项目从sdk管理器下载系统镜像(项目的目标android级别)。

This error comes when you do not have target sdk of your android project installed in sdk folder

当在sdk文件夹中没有安装android项目的目标sdk时,就会出现此错误

for eg. Your imported project's target sdk level may be android-19 and on sdk folder->system-images you may have android-21 installed. so you have to download android-19 system image and other files from sdk manager or you can copy paste it if you have the system image.

如。您导入的项目的目标sdk级别可能是android-19,在sdk文件夹——>系统镜像中,您可能已经安装了android-21。所以你必须从sdk管理器下载android-19系统镜像和其他文件,如果你有系统镜像,你也可以复制粘贴。

#3


13  

Remove:

删除:

<facet type="android" name="Android">
    <configuration />
</facet>

in your iml file. That works for me.

安恩科技文件中。这适合我。

https://plus.google.com/+AlexRuiz/posts/49hP3V9GSGe

https://plus.google.com/ + AlexRuiz /文章/ 49 hp3v9gsge

#4


9  

This happened to me recently when I close one Android Studio project and imported another Eclipse project. It seemed to be some bug in Android Studio where it preserves some gradle settings from previously open project and then get confused in the new project.

最近,当我关闭一个Android Studio项目并导入另一个Eclipse项目时,我就遇到了这种情况。这似乎是Android Studio中的一个bug,它保留了以前开放项目中的一些等级设置,然后在新项目中出现了混乱。

The solution was extremely simple: Close the project and shut down Android Studio completely, before re-opening it and then import/open the new project. Everything goes smoothly from then on.

解决方案非常简单:关闭项目并完全关闭Android Studio,然后重新打开它,然后导入/打开新项目。从那时起一切都很顺利。

#5


4  

Simple fix for me was

对我来说,简单的解决办法是

  1. Build > Clean project
  2. 构建>清洁项目
  3. Restart Android Studio
  4. 重新启动Android工作室

#6


3  

Apparently this error has multiple causes. Here's what fixed it for me.

显然,这个错误有多种原因。这是我修复它的方法。

I was running the build command like this:

我运行的构建命令如下:

./gradlew :testapp: build

Running it without the space fixed the issue:

在没有空格的情况下运行,解决了问题:

./gradlew :testapp:build

#7


2  

In my case, setting the 'Gradle version' same as the 'Android Plugin version' under File->Project Structure->Project fixed the issue for me.

在我的例子中,>项目结构下的“Gradle version”与“Android Plugin version”相同,>项目为我解决了这个问题。

#8


2  

Sometimes, if you have opened two windows of Android Studio, and when you try to compile, this issue might happen. For me, when I was compiling a backed Google Cloud Endpoint module which was not embedded in a project, rather shared among different Android Studio projects, and when there is more than once instance open, this error use to spring up for me. But as soon as you close other windows, everything will be fine. Sometimes, you might have to restart Android Studio altogether.

有时,如果您打开了Android Studio的两个窗口,当您尝试编译时,这个问题可能会发生。对我来说,当我编译一个备份的谷歌云端点模块时,它没有嵌入到一个项目中,而是在不同的Android Studio项目*享,当有多个实例打开时,这个错误就会出现。但只要你关上其他窗口,一切都会好起来的。有时,你可能不得不重新启动Android Studio。

#9


1  

Make sure you have the latest values in your gradle files. As of this writing:

确保您的等级文件中有最新的值。在撰写本文时:

  • buildToolsVersion "21.1.2"

    buildToolsVersion“21.1.2”

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

    依赖项{类路径'com.android.tools.build:gradle:1.1.0'}

#10


1  

Yet another solution to the same problem:

同样问题的另一个解决办法是:

This happened to me every time I imported an eclipse project into studio using the wizard (studio version 1.3.2).

每次我使用向导(studio version 1.3.2)将eclipse项目导入studio时,就会发生这种情况。

What I found, quite by chance, was that quitting out of Android studio and then restarting studio again made the problem go away.

我很偶然地发现,退出Android studio,然后重新启动studio,这个问题就解决了。

Frustrating, but hope this helps someone...

令人沮丧,但希望这能帮助某人…

#11


1  

I got this error when switching from one Git branch to another, and then trying to run "Clean Project". I used ack to search for the Task name, and found it in a .iml file.

在从一个Git分支切换到另一个Git分支时,我得到了这个错误,然后尝试运行“Clean Project”。我使用ack搜索任务名,并在一个.iml文件中找到它。

My solution was to regenerate the project's .iml file by clicking (in the main menu) Tools > Android > Sync Project with Gradle Files. (Thanks to this answer.)

我的解决方案是通过点击(在主菜单中)工具> Android > Sync项目来重新生成项目的.iml文件。(由于这答案。)

#12


0  

Set the path of the root folder and after run the below command

设置根文件夹的路径,并运行以下命令。

ex : cd C:\Users\maha\Documents\gradle\gs-gradle-master\initial

#13


0  

This is what I did

这就是我所做的

  1. Remove .idea folder

    删除.idea文件夹

    $ mv .idea .idea.bak

    美元mv .idea .idea.bak

  2. Import the project again

    再次导入项目

#14


0  

I remove/Rename .gradle folder in c:\users\Myuser\.gradle and restart Android Studio and worked for me

我删除/重命名.gradle文件夹在c:\用户\Myuser\ \ \。葛拉德和重启Android Studio,并为我工作

#15


0  

  1. Open Command Prompt
  2. 打开命令提示符
  3. then go your project folder thru Command prompt
  4. 然后通过命令提示符进入项目文件夹
  5. Type gradlew build and run
  6. 类型级配流构建和运行。

#16


0  

Apparently this issue caused by Android Studio on the various situation but the reason is build error When importing an existing project into android studio.

In my case, I've imported my exist project where I was supposed to install few build tools then finally build configuration was done with error. In this case, just do the following things

显然这个问题是由Android Studio在各种情况下引起的,但是原因是在将一个现有项目导入Android Studio时出现了构建错误。在我的例子中,我导入了我的exist项目,在那里我应该安装很少的构建工具,然后最终构建配置是错误的。在这种情况下,只需做以下事情

  1. Close the current project
  2. 关闭当前项目
  3. File>New>Import Project (Don't use the open recent project)

    Note: I'm sure this kind of error is not on source code when this happened on Import project.
  4. 文件>新的>导入项目(不要使用最近的开放项目)注意:我确信当导入项目发生这种情况时,这种错误不在源代码中。

#17


0  

Problem

I specifically got the "[module_name]:prepareDebugUnitTestDependencies" task not found error, every time I ran gradle build. This happened to me after updating my Android Studio to 3.0.0.

我特别得到了“[module_name]:prepareDebugUnitTestDependencies”任务没有发现错误,每次我运行gradle构建。这发生在我将Android Studio更新为3.0.0之后。

Investigation

I had previously added command-line options to the gradle-based compiler, which you can find under: File -> Settings -> Build, Execution, Deployment -> Compiler -> Command-line Options. Specifically, I had excluded a number of tasks, including the aforementioned task. While that worked fine on the previous stable version (2.3 at that time), it seems like this was the reason behind the build failure.

我之前已经向基于级别的编译器添加了命令行选项,您可以在下面找到:File—>设置—>构建、执行、部署—>编译器—>命令行选项。具体地说,我排除了一些任务,包括前面提到的任务。虽然在以前的稳定版本(当时是2.3)上运行良好,但这似乎是导致构建失败的原因。

Solution

This is one of many possible solutions. Make sure you have the correct command-line options specified in the settings under: File -> Settings -> Build, Execution, Deployment -> Compiler -> Command-line Options, and that none of them is causing this problem.

这是许多可能的解决方案之一。请确保在以下设置中指定了正确的命令行选项:File ->设置->构建、执行、部署->编译器->命令行选项,并且它们都不会导致这个问题。

In my case, I removed the exclusion of this task (and other tasks that seemed related), left the unrelated tasks excluded, and it worked!

在我的例子中,我删除了这个任务(以及其他看起来相关的任务)的排除,将不相关的任务排除在外,并且它工作了!