Gradle build: Execution failed for task ':app:

2019-02-05 19:47发布

问题:

I'm using Android Studio 2.0 and I was trying to running my program when something strange happened. I ran the build command of the gradle and I got this error:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:lint'.
> Lint found errors in the project; aborting build.

Fix the issues identified by lint, or add the following to your build script to proceed with errors:
...
android {
    lintOptions {
        abortOnError false
    }
}
...

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 4.197 secs
Lint found errors in the project; aborting build.

Fix the issues identified by lint, or add the following to your build script to proceed with errors:
...
android {
    lintOptions {
        abortOnError false
    }
}
...
10:41:28: External task execution finished 'build'.

And so... What the hell is that? I'm supposed to do to solve this problem adding the code to the gradle.build, but the question is: why I got this error message?

Please save me guys!

回答1:

Add this in your build.gradle

android {
    lintOptions {
        abortOnError false
    }
}


回答2:

You have some lint issues while you are bulding the app module.

You can find all issues found in the report generated in Project\module\build\outputs.
Here you will find the html file and the xml file with the lint report.

Using this script in the app\build.gradle

android {
    lintOptions {
        abortOnError false
    }
}

you can disable the block but it is not the best practice.
You should analyze the lint report to solve each point.



回答3:

  1. Switch to project view
  2. Then, project/app/build/reports/lint-results
  3. Now, you will find the lint-result files in two formats - 1) xml and 2) html.

You can view these files as is. However, I find viewing the lint results in a browser to be easy on the eyes. Just right-click on the html file and choose view in browser.

It opens up like the image below in my Chrome browser.



回答4:

I think it's better to find the errors rather than ignoring them.

try this:

In Gradle Console find "Wrote HTML report to file", open the indicated HTML file and you will find a lint report

Go to your errors and fix them



回答5:

Your build.gradle(Module: app) should include


android {
    lintOptions {
        abortOnError false
    }
}



回答6:

Run gradle build -i instead of just gradle build. There will be lots more output than usual. Some of it will look like this:

> Task :project-name:lint FAILED
Putting task artifact state for task ':project-name:lint' into context took 0.0 secs.
Up-to-date check for task ':project-name:lint' took 0.0 secs. It is not up-to-date because:
  Task has not declared any outputs.
Ran lint on variant release: 333 issues found
Ran lint on variant debug: 333 issues found
Wrote HTML report to file:///some/path/lint-results.html
Wrote XML report to file:///some/pahth/lint-results.xml

:project-name:lint (Thread[Task worker for ':',5,main]) completed. Took 1.756 secs.

Check out /some/path/lint-results.html to see why lint failed. Once those errors are fixed, your build will complete smoothly.



回答7:

I got the error Execution failed for task ':app:lintVital[myBuildVariant]' and a nullpointer error. It happened after switching branches and the thing that helped for me was to do a Build -> Clean Project



回答8:

Only add this code in build gradle:

android {
    lintOptions {
        abortOnError false
    }
}

That should be enough.