40

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!

Davide
  • 513
  • 1
  • 4
  • 9

9 Answers9

51

Add this in your app/build.gradle file

android {
    //...
    lintOptions {
        abortOnError false
    }
}
Vinicius Almada
  • 309
  • 2
  • 11
Pinks
  • 730
  • 6
  • 9
  • 8
    I got that, but I was looking for the cause of the error... Why would it appear? – Davide Apr 26 '16 at 09:10
  • For further viewers, make sure you're referencing the right `build.gradle` *within* your project - https://stackoverflow.com/questions/37250493/could-not-find-method-android-for-arguments – eouw0o83hf Jun 29 '17 at 23:11
  • How about if a warning message, "Access is denied" pop out when I try t add this code into build.gradle.? – Cayenne Teoh Jul 28 '17 at 07:41
  • There are many `build.gradle`s in RN and, as the last answer specifies, use `build.gradle(Module: app)`. – Garrett Oct 24 '17 at 01:15
  • Is there a command-line switch to act like temporarily `abortOnError=false` without permanently adding it to the `build.gradle` file? – MarkHu Mar 29 '18 at 06:44
  • I wrote in build.gradle file. but Could not find method android() for arguments [build_9bspgiibcb79q5zrs1id49jgw$_run_closure2@4797b8b] on root project 'kazoemon' of type org.gradle.api.Project. – shinriyo Nov 04 '18 at 07:29
  • It is not a good solution. Sometimes, it causes real issues in release apk. – Amir Shabani Jan 22 '19 at 06:41
  • How to do this in gradle .kts? – IgorGanapolsky Apr 05 '21 at 20:05
20

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.

Gabriele Mariotti
  • 192,671
  • 57
  • 469
  • 489
  • 4
    Thanks for pointing to the report. But why aren't those warnings integrated into Android Studio? I thought this IDE is so much better than ADT. – OneWorld Nov 24 '16 at 13:39
  • You should specify that the short script addition you advice, belongs to the Module:app part of build.gradle. – Sold Out Aug 06 '17 at 15:49
  • @GabrieleMariotti You are right. I changed my mind soon after, but it was late already :\ If you'd edit ur answer i'll be able again to cancel my down vote :) – Sold Out Aug 06 '17 at 16:17
19
  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.

Screenshot of lint results

Avid Programmer
  • 862
  • 1
  • 8
  • 20
9

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

HTML lint report

Jorge Arimany
  • 5,013
  • 2
  • 26
  • 21
3

Your build.gradle(Module: app) should include


android {
    lintOptions {
        abortOnError false
    }
}

duggu
  • 35,841
  • 11
  • 112
  • 110
Blaq
  • 39
  • 1
0

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.

MatrixManAtYrService
  • 5,337
  • 34
  • 46
0

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

lejonl
  • 1,363
  • 13
  • 18
0

If you face this issue do not add a linter disabler to your gradle, This is an access error issue,I faced that on react-native after using sudo command for a few command, Just reset your code access and then release again For example the mac

sudo chmod -R 777 <project-root-folder-name>

If it remains use

preBuild.doFirst { 
ant.replaceregexp(
    match:'Bad gradle', 
    replace:'Correct one', 
    flags:'g', 
    byline:true
) { 
    fileset(
        dir: 'Where to search', 
        includes: '*.java'
    ) 
} 
}

So you can fix error before release if exists in that library

Mohammad f
  • 437
  • 6
  • 10
-1

Only add this code in build gradle:

android {
    lintOptions {
        abortOnError false
    }
}

That should be enough.

Madhur Bhaiya
  • 26,097
  • 10
  • 39
  • 51