An Android Studio build failure with a Task was not found in the root project My Project.

I get this error when trying to create my project after changing the laptop and updating to version 0.8.2 for Android.

FAILURE: assembly failure with exception.

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

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

STRICTLY MALFUNCTIONAL

Here are my gradle files:

Top Level Settings .gradle

include ':MyProject' 

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

The top level of build.gradle is empty

+75
android android-studio build gradle
Aug 6 '14 at 23:35
source share
17 answers

Despite being late in the answer, it is difficult for Google (single quotes), and it is not clear what is going on. I don't have a reputation yet to comment or request volume (or send 3 links), so this answer can be a bit tedious.

To answer quickly, you may have several Gradle plugins in your project.

Sync Gradle Wrapper and Plugins

My problem started with a damaged IML file. Android Studio (between closing and reopening the project) started complaining that IML was gone (it wasn’t), and the module should be removed, and I refused. It was saved, I upgraded to AS 0.8.7 (channel channel) and got stuck in the OP problem (task "not found in the root project"). This completely blocked assemblies, so I had to fall into Gradle.

My recovery steps on OSX (please configure for Windows):

  • Update Android Studio to 0.8.7
    • Settings | Updates | Switch Beta Channel to Channel Channel, then test now.
    • You may be able to skip this.
  • Checked Gradle wrapper (currently 1.12.2; do not try to use 2.0 at this time).

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

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

    • This can be installed in Android Studio in the settings | Gradle (but 0.8.7 gave me "wrong location errors").

    • "wrapper" is just a copy of Gradle for every Android Studio project. This allows you to have Gradle 2 in your OS and different versions of your projects. Android developer docs explain what's here .
    • Then edit the build.gradle files for the plugin. The Gradle plugin version must be compatible with the distribution / wrapper version for the entire project. Since the documentation for the tools (tools.android.com/tech-docs/new-build-system/user-guide#TOC-Requirements) is a bit outdated, you can install the plugin version too low (for example, 0.8) and Android Studio will output error with a valid range for the shell.

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, for example:

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

and (after recording which version you are changing in each case), checking that each build.gradle file in your project pulls out the same version of the plugin. Saving "+" should work (for 0.12.0, 0.12.1, 0.12.2, etc.), but my build ended when I updated the Googles Volley library (originally gradle: 0.8. +) And my main project (initially 0.12. +) Before the fixed version: gradle: 0.12.2.

Other checks

  • Make sure you do not have two Android application modules in the same project

    • This can interact with the final solution (different versions of Gradle above) and cause

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

    • To check, build | Make a project should not appear in the window asking what application you want to make.

  • Invalid Caching
    • File | Invalidate Caches / Restart (stackoverflow.com/a/19223269/513413)
  • If step 2 does not work, delete ~ / .gradle / (www.wuttech.com/index.php/tag/groovy-lang-closure/)
    • Quit Android Studio
    • $ rm -rf ~ / .gradle /
    • Launch Android Studio, then sync:
      • Tools | Android | Synchronize a project using gradle files
    • Repeat this sequence (quit ... sync) several times before giving up.
  • Clear project
    • Assembly | Clean project

If you see this ...

In my latest builds, I continued to see terrible failures (exception pages), but after a few seconds the messages were cleared, built successfully and the application was deployed. Since I could never explain this, and the application worked, I never noticed that I had two Gradle plugins in my project. So I think Gradle plugins fought each other; one crashed, the other lost his condition and reported an error.

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

Renouncement

I study this whole stack in a foreign OS, working in a different career ... all at the same time and under pressure. In the past few months, I have run into every wall, I think Android has; I have been here quite often, and this is my first post. I thought this was a difficult decision, so I sincerely apologize if the quality of my answer reflects the difficulty that I encountered.

+57
Aug 27 '14 at 10:58
source share

Download the system image (Android target level of your project) from the sdk manager for the imported project.

This error occurs when you do not have the target sdk of your Android project in the sdk folder

eg. At your target level, the sdk of the target target project can be android-19 and sdk folder-> system-images on which Android-21 is installed. so you need to download the android-19 system image and other files from the sdk manager or you can copy it if you have a system image.

+22
Dec 17 '14 at 9:22
source share

Delete

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

in your iml file. This works for me.

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

+13
Feb 01 '15 at 4:33
source share

This happened to me recently when I closed one Android Studio project and imported another Eclipse project. It seemed like some error in Android Studio, where it saves some gradle options from a previously open project, and then gets confused in a new project.

The solution was very simple: close the project and shut down Android Studio completely before opening it again and then importing / opening a new project. Since then, everything has been going smoothly.

+9
Apr 29 '15 at 11:38
source share

A simple fix for me was

  • Build> Clear Project
  • Restart Android Studio
+4
Sep 18 '15 at 3:14
source share

Apparently, this error has several reasons. Here is what fixed it for me.

I ran the build command as follows:

 ./gradlew :testapp: build 

Running without fixing the problem:

 ./gradlew :testapp:build 
+3
Apr 6 '15 at 19:46
source share

In my case, installing a version of "Gradle" similar to the version of "Android Plugin" in the "File-> Project Structure-> Project" section fixed the problem for me.

+2
Mar 11 '15 at 10:59
source share

Make sure you have the latest values ​​in the gradle files. At the time of this writing:

  • buildToolsVersion "21.1.2"

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

+1
Feb 27 '15 at 20:18
source share

Another solution to the same problem:

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

What I discovered, quite by accident, was that exiting Android studio and restarting the studio again made the problem go away.

Disappointing, but hope this helps someone ...

+1
Aug 25 '15 at 17:07
source share

Sometimes, if you open two windows of Android Studio, and when you try to compile, this problem can happen. For me, when I compiled a supported Google Cloud Endpoint module that was not built into the project, it was quite common among different Android Studio projects, and when more than one instance of the instance was open, this error is used for spring for me. But as soon as you close the other windows, everything will be fine. Sometimes you may need to completely restart Android Studio.

+1
Feb 05 '17 at 16:26
source share

Set the path to the root folder and run the following command.

 ex : cd C:\Users\maha\Documents\gradle\gs-gradle-master\initial 
0
Apr 02 '15 at 6:42
source share

This is what I did

  • Delete .idea folder

    $ mv.idea.idea.bak

  • Import the project again

0
Jul 30 '15 at 10:19
source share

I delete / rename the .gradle folder to c:\users\Myuser\.gradle and restart Android Studio and work for me

0
Aug 11 '15 at 13:09 on
source share
  • Open command line
  • then go to the project folder through the command line
  • Type gradlew build and run
0
Aug 29 '15 at 10:14
source share

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

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

0
Jan 03 '17 at 18:35
source share

Apparently, this problem is caused by Android Studio in a different situation, but the reason is a build error when importing an existing project into android studio.

In my case, I imported my existing project, where I had to install several build tools, and then finally the configuration failed. In this case, follow these steps:

  • Close current project
  • File> New> Import Project (do not use open project)

    Note: I am sure that such an error is not in the source code when it happened in the Import project .
0
Oct 11 '17 at 15:57
source share

Problem

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

Study

I previously added command-line options to the gradle compiler, which you can find in the section: File -> Options -> Build, Run , Deploy -> Compiler -> Command-Line Options . In particular, I excluded a number of problems, including the aforementioned problem. While this worked well on the previous stable version (2.3 at the time), it looks like this was causing the build to fail.

Decision

This is one of many possible solutions. Make sure that you have the correct command line parameters specified in the settings in the section: File → Settings → Build, Run, Deploy → Compiler → Command Line Parameters and that none of them are causing this problem.

In my case, I removed the exception for this task (and other tasks that were related), left the unrelated tasks excluded, and it worked!

0
Oct 26 '17 at 7:48 on
source share



All Articles