Gradle build: Execution failed for task ':app:lint' - android

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!

Add this in your app/build.gradle file
android {
//...
lintOptions {
abortOnError false
}
}

Switch to project view
Then, project/app/build/reports/lint-results
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.

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.

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

Your build.gradle(Module: app) should include
android {
lintOptions {
abortOnError false
}
}

If the abortOnError false does not work, the Flutter version 2.5.1 recommend using the following arguments in the lintOptions:
android{
...
lintOptions {
checkReleaseBuilds false
}
}

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.

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

Only add this code in build gradle:
android {
lintOptions {
abortOnError false
}
}
That should be enough.

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

The new lint way is like so
android {
lint {
isAbortOnError = false
}
}

Related

How to tell gradlew to export lint results file to projectDir?

I'm building an Android application using Jenkins pipeline and Gradle.
I'd like to run Lint tests on the code and so the command which is used for that matter is:
./gradlew lintStagingDebug
For some reason this Gradle task is not creating the report.
I know that if I'd run lint like so:
lint <project_dir> --xml xml_dest_path
It would create the report.
But since through out the whole pipeline I'm using gradlew to run the relevant tasks (clean, lint, compile, unittest, assemble) I'd like to use gradlew for this task as well but I'm not sure how to tell Gradle to export the lint report.
Another thing I've tried is to edit the project/build.gradle file and change this section:
lintOptions {
abortOnError false
}
to (according to Lint official documentation)
lintOptions {
abortOnError false
xmlOutput projectDir/lint-results.xml
}
But then I get an error:
A problem occurred evaluating project ':App01'.
> No signature of method: java.io.File.div() is applicable for argument types: (com.android.build.gradle.tasks.Lint_Decorated) values: [task ':App01:lint']
Anyone knows how it can be done?
You can provide the XML report output file in Gradle in the following way:
lintOptions {
xmlOutput file("lint-results.xml")
}
The xmlOutput method requires a file type argument. I have used the relative path in the argument. You can also use it with projectDir.
lintOptions {
xmlOutput file("$projectDir/lint-results.xml")
}
Here's how I solved it.
stage('Lint run') {
sh """
export HOME=$GRADLE_USER_HOME
export JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64"
OUTPUTFILE="lint-results.txt"
touch \$OUTPUTFILE
./gradlew lint${BUILDFLAV}${BUILDTYPE} -x lint 2>&1 | tee \$OUTPUTFILE
"""
})
Explanation:
In order to keep using gradlew to run lint test on the code, I've defined an output file and added at the end of the gradlew command redirection of stdOut and stdErr to this output file using the Linux command "tee".

Add lint to CI and mark a build fail when lint produces errors for Android Studio projects

I need the Gradle build to be marked as a failure and it should be stopped automatically if running lint gives me an error. I made the changes in code as required but it did not result in any change.
Code:
lintOptions {
// set to true to turn off analysis progress reporting by lint
quiet true
// if true, stop the gradle build if errors are found
abortOnError true
// if true, only report errors
ignoreWarnings false
}
Also apart from it, I need to add lint to CI. The CI software I use is Jenkins. SO I need to configure their android linting plugin of Jenkins such that the build is stopped and marked Failure if Lint gives an error.
I am very new to lint and CI, so please provide a detailed answer.
You don't need the Lint Jenkins plugin. Just put something this in your JenkinsFile.
try {
sh './gradlew lint'
} finally {
step([$class: 'ArtifactArchiver', artifacts: 'app/build/reports/staticAnalysis/lint/', fingerprint: true])
}
ArtifactArchiver is just to collect artifacts after lint check.

Gradle tests report for Android Tests

Can I have gradle tests report for android tests? I want to have the report directly in the terminal. Every time a test is passed, failed or skipped I want to have the report printed in the terminal with the name of the test and the status.
For Unit tests I can add this to the gradle file to have the reports:
tasks.withType(Test) {
testLogging {
exceptionFormat "full"
events "passed", "skipped", "failed"
}
}
I didn't find any solution to the android tests.
You can try this (add to app/library build.gradle)
tasks.withType(com.android.build.gradle.internal.tasks.AndroidTestTask) { task ->
task.doFirst {
logging.level = LogLevel.INFO
}
task.doLast {
logging.level = LogLevel.LIFECYCLE
}
}
There's a bug filed to the Platform tools team that is still not resolved:
https://code.google.com/p/android/issues/detail?id=182307
You can vote it to help. The workaround didn't work for me, but if you use Gradle Plugin >= 1.5.0 you can run the command with info logs enabled like this:
./gradlew cC --info
and then you'll see the tests being printed with no extra configuration.
Hope it helps!
Have you tried looking into app/build/reports/tests/debug/index.html or app/build/test-results/?
By using the new test support library you should find your reports there, with no extra-configuration needed.
I've made some investigation, and universal variant to show unitTests and AndroidTests in the terminal is put '--debug' option on the gradle terminal command.
Example:
./gradlew cleanTestDebugUnitTest testDebugUnitTest cleanConnectedDebugAndroidTest connectedDebugAndroidTest --debug

Suppress successful lint output in Gradle

Is there a switch to turn off the lint output like this:
:app:lint
Ran lint on variant release: 0 issues found
Ran lint on variant debug: 0 issues found
Wrote HTML report to file:/.../project/app/build/outputs/lint-results.html
Wrote XML report to .../project/app/build/outputs/lint-results.xml
It should be pretty obvious from a
:app:lint
:app:nextTaskAfterLint
output that:
Lint ran
No issues found
No-one wants to look at an almost empty html page saying "Congratulations!"
I tried these options:
android {
lintOptions {
quiet true // no effect at all
textOutput file('lint.x') // no output to given file, and still outputs to stdout
}
}
It would be nice to have the above output if the issues found is > 0, but it's not a big problem since I can stop the build by warningsAsErrors true and abortOnError true if any issues found.
According to doc, you can exclude a task with a command line:
http://www.gradle.org/docs/current/userguide/userguide_single.html#sec%3aexcluding_tasks_from_the_command_line
So you can use this command to skip lint:
gradlew build -x lint
To avoid the log output, you can check the Lint task here:
https://android.googlesource.com/platform/tools/base/+/gradle_0.13.3/build-system/gradle/src/main/groovy/com/android/build/gradle/tasks/Lint.groovy
You can find at line 90:
if (!mFatalOnly) {
println "Ran lint on variant " + variant.getName() + ": " + warnings.size() +
" issues found"
}
Hovewer I didn't find how to set this variable-
Here you can find all options available today with the gradle plugin 0.13.3:
https://android.googlesource.com/platform/tools/base/+/gradle_0.13.3/build-system/builder-model/src/main/java/com/android/builder/model/LintOptions.java

How to remove lint errors in android studio

when i was trying to execute my android studio wear application it shows lint error.
Here is my log :
Error:Execution failed for task ':wear: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
}
}
...
Add this to your build.gradle file
android {
lintOptions {
abortOnError false
}
}
Add this to your module level build.gradle file
> lintOptions {
> abortOnError false
> }
This will stop aborting of gradle if any lint error found, even though this is not recommended.
Alternatively you can just go to yourproject>app>build>results>lint_error.htmland then see errors and solve them or, you can also go for,
Analyze>Inspect Code and solve errors beforehand.
Hope this will solve your query.

Categories

Resources