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
Related
I'm trying to update a project to Android Studio 3.
The following snippet is no longer accepted in a build.gradle file.
applicationVariants.all { variant ->
variant.outputs.each { out ->
def oFile =out.outputFile // This line causes failure
//...
}
}
The error is a simple "Not Valid" yet the intellisense suggests it is as it autocompletes fine.
Checking the idea.log shows the following exception:
Caused by: java.lang.RuntimeException: Not valid.
at com.android.ide.common.build.ApkData.getMainOutputFile(ApkData.java:136)
at com.android.build.gradle.internal.api.BaseVariantOutputImpl.getOutputFile(BaseVariantOutputImpl.java:60)
at com.android.build.gradle.internal.api.ApkVariantOutputImpl_Decorated.getOutputFile(Unknown Source)
at org.gradle.internal.metaobject.BeanDynamicObject$MetaClassAdapter.getProperty(BeanDynamicObject.java:228)
at org.gradle.internal.metaobject.BeanDynamicObject.tryGetProperty(BeanDynamicObject.java:171)
at org.gradle.internal.metaobject.CompositeDynamicObject.tryGetProperty(CompositeDynamicObject.java:55)
at org.gradle.internal.metaobject.AbstractDynamicObject.getProperty(AbstractDynamicObject.java:59)
at com.android.build.gradle.internal.api.ApkVariantOutputImpl_Decorated.getProperty(Unknown Source)
I can find no documentation on Gradle 4. Would this be a bug or a function that is deprecated perhaps?
Also filed at: https://issuetracker.google.com/issues/38408231
Update: Fix for APK renaming:
Use all iterators instead of each:
android.applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = "${variant.name}-${variant.versionName}.apk"
}
}
Previous answer, still valid: It's a known problem with the new plugin:
This build error occurs because variant-specific tasks are no longer created during the configuration stage. This results in the plugin not knowing all of its outputs up front, but it also means faster configuration times. As an alternative, we will introduce new APIs to provide similar functionality.
We need to wait for an alternative way of doing that, according to the Migration Guide.
If your failing plugin support explicitly setting file path, it might be a work around.
I had problems with Fabrics crashlyticsUploadDistributionRelease task, giving me the same stack trace as above. I fixed it by explicitly setting the output file path property in app/build.gradle:
ext.betaDistributionApkFilePath = "app/build/outputs/apk/release/app-release.apk"
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".
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.
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
}
}
I'd like strings.xml to be checked for spelling while building with gradle. Since we use continuous integration we need it to be configured for building from command-line not just in Android Studio. Any way to do it?
PS. I've tried:
lintOptions {
abortOnError false
// check *only* the given issue id's
check 'Typos'
}
strings.xml:
<resources>
<string name="app_name">Project</string>
<!-- Common Words -->
<string name="test_spelling">sdfsdfdfds</string>
and
./gradlew assembleDebug lint
but got nothing:
:app:lint
Ran lint on variant release: 0 issues found
Ran lint on variant debug: 0 issues found
Wrote HTML report to file:/Users/asmirnov/Documents/dev/src/Project/app/build/outputs/lint-results.html
Wrote XML report to /Users/asmirnov/Documents/dev/src/Project/app/build/outputs/lint-results.xml
Also i've checked lint --show :
...
Typos
-----
Summary: Spelling error
Priority: 7 / 10
Severity: Warning
Category: Correctness:Messages
This check looks through the string definitions, and if it finds any words
that look like likely misspellings, they are flagged.
...
PPS. If i add another rule to check (check 'Typos', 'TypographyEllipsis') i'm getting warnings (for TypographyEllipsis) as expected, so in general linting works. For some reason "Typos" rule is not working only
I am currently working on something similar, so have not completed my work. Not sure if you have an answer as yet, as it was asked a while ago. Here is what I have.
The code you have here:
lintOptions {
abortOnError false
// check *only* the given issue id's
check 'Typos'
}
should be fine. You can also add it within a flavor, to be more restrictive, if you are using them.
To get the report from the command line, you need to execute:
./gradlew lintAssembleDebug
or whatever your flavor is, e.g. ./gradlew lintAssembleMyFlavorDebug
I am trying to make use of the lintOptions.check() method, to programmatically add the checks I want, but no luck yet. Another alternative is as described here by Jason Atwood. I am looking at this, adding the blank file:
ext.lintCheckList = [
// Blank default list
] as String[]
to the repo, and replacing that in the CI job, as needed.
Hope that helps.
Update:
The command is incorrect. It should be
./gradlew lintDebug
or
./gradlew lintMyFlavorDebug
etc
If you do want spell check feature that is enabled by default in Android Studio IDE then follow the below given steps,
Go to Android Studio -> Preferences on your Mac OS X (Should be Window -> Preferences on Windows OS)
Now look for Inspections (if you cant trace it just use the Search)
Now look for the Spellings check box and check it (this also checks the Typo)
Apply and Close
Thats it!! You would now see any Typo or spelling correction highlights in Android Studio.