How to configure lint by gradle options from command line? - android

Is there any way to set abortOnError false for lint by command line options of gradle/gradlew, without gradle config changing?

There may be a more direct way to do this, but I recently solved this problem by setting abortOnError based on a project property that can be overwritten from the command line.
Something like this:
lintOptions {
abortOnError project.hasProperty("abortOnLintError") ? project.getProperty("abortOnLintError").toBoolean() : false
}
By default, abortOnError is set to false, but if you want to overwrite it to true from the command line, you can:
./gradlew lintDebug -PabortOnLintError=true

Related

Lint found fatal errors

While generating release in android studio Build--> Generating signed Bundle/APK(s), I got below message
"Lint found fatal errors while assembling a release target", because of this I am unable to generate the release build
Try this:
lintOptions {
checkReleaseBuilds false
}
to app level build.grade file within the android{ } section.
In your Android Studio, switch to the Project pane. Go app --> build
--> reports --> lint-results-prodRelease-fatal.xml
Here android studio will open the file explaining the error, message, and the place and line number where it has occurred.
Now in 2022, the path to lint output might be changed. please check in For me I found the error mentioned in this path
app\build\intermediates\lint_vital_intermediate_text_report\release\lint-results-release.txt
a work around but will not solve the real problem and you might face troubles in production is to change below true to false. but I don't recommend it.
android {
lintOptions {
checkReleaseBuilds true
abortOnError true
}

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.

Cannot see parameter value in Android Studio when breakpoint is in first line of a method

I am just switching from Eclipse to Android Studio and found this weird behavior. When I add a breakpoint in the first line of a method, I cannot see the parameter values. The only thing I can see then is the this reference. I either have to make one debug step or set the breakpoint to a line after the first one to see the parameter values.
Anyone else has this problem or knows what's going wrong here?
Try turning off your jacoco test coverage off for the debug build in your build.gradle file:
debug {
...
testCoverageEnabled false
}
This completely fixed the issue for me where upgrading the gradle plugin did not.
A good solution until AOSP Issue #123771 is solved, is to use the snippet provided by Stuart in the comments section:
buildTypes {
debug {
[...]
testCoverageEnabled true
}
release {
[...]
}
debuggable.initWith(buildTypes.debug)
debuggable {
testCoverageEnabled false
}
}
This way you can both keep your test coverage reports in your debug build and have a way of stepping through code seeing your local variables.
I don't have in my gradle file:
debug {
...
testCoverageEnabled true
}
but had the same issue on Android Studio 2.2. Solution that helped me to resolve issue:
Disable Instant Run in IDEA Settings.
Re-build project.
Enable Instant Run.
The solution provided by Google here is to upgrade the Android Studio Gradle plugin to v1.0.1
If your build uses the jack toolchain this can be the source of the problem. In my case, disabling jack solves the problem:
buildTypes {
...
debug {
jackOptions {
enabled false
}
}
}
Note: 1.8 source compatibility requires jack!
I got sick of toggling testCoverageEnabled when I wanted to debug so set up a project property to disable it when run from Android Studio, but default to enabled when run from command line with no options such as on a build box.
// Default to true, set -PtestCoverageEnabled=false in IDE compiler command-line options
def isTestCoverageEnabled = { ->
def enabled = project.hasProperty('testCoverageEnabled') ? testCoverageEnabled.toBoolean() : true
println "testCoverageEnabled = " + (enabled ? "true" : "false")
return enabled
}
android {
buildTypes {
debug {
testCoverageEnabled isTestCoverageEnabled()
}
}
}
To set the property in the IDE add the command-line option -PtestCoverageEnabled=false
Android Studio -> Preferences -> Build, Execution, Deployment -> Compiler -> Command-line Options
I ran into this issue when trying to debug an app that was previously installed using an APK and not from Android Studio itself. Fixed it by uninstalling the app and re-run the debug.
Following configuration worked for me for buildType release.
buildTypes {
release{
testCoverageEnabled = false
debuggable true
minifyEnabled false
shrinkResources false
}

How to sign APK on Android Studio even with non-translated strings?

Background
I've recently migrated my app to Android-Studio. I had some issues doing so, but I got over them eventually.
The problem
For some reason, on Android Studio, when I try to sign an APK, I get a lot of errors that look like this:
Error:(16) Error: "..." is not translated in "de" (German), "el" (Greek), "iw" (Hebrew) [MissingTranslation]
(where "..." is a string)
At the bottom, after a lot of errors of this kind, I see this:
Error:Execution failed for task ':app:lintVitalRelease'.
> Lint found fatal errors while assembling a release target.
To proceed, either fix the issues identified by lint, or modify your build script as follows:
...
android {
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
}
...
The question
I'm not sure what's wrong and how I can fix it. On Eclipse I did it very easily. Missing translations shouldn't stop me from signing an APK...
To me it seems as if Lint is preventing the exporting of the APK, and that the reason is that I didn't translate all of the strings. Is that true?
Can anyone please help me? How can I fix this, so that Lint will show me just warnings instead? or a confirmation dialog if I'm sure I want to do it?
The cleanest way to solve the problem is to disable Lint checks of missing translations for release builds only.
To do so add "disable 'MissingTranslation'" to your build.gradle file as shown below:
android {
buildTypes {
release {
lintOptions {
disable 'MissingTranslation'
}
}
}
}
To me it seems as if Lint is preventing the exporting of the APK, and
that the reason is that I didn't translate all of the strings. Is that
true?
Yes. Default option is lintOptions.abortOnError = true
Can anyone please help me?
You should open the build.gradle file located at the main project module, or the generic folder if you do not have a module. Then add the suggested lines:
android {
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
}
Some Lint warnings are by default turned to studio as errors, I don't actually know why, but in terms of translations I guess that is a way to "stop" you publishing an app that the translation is incomplete due to a last minute additions of some texts.
With the lintOptions checkReleaseBuilds abortOnError you set the checking of Lint not to run for release versions and also not stopping if an "error" is found. Below I explain where the Lint errors settings can be found, so if you want to go further you can go one step forward and read them one by one. Some of them provide helpful instructions for code optimizations.
How can I fix this, so that Lint will show me just warnings instead?
or a confirmation dialog if I'm sure I want to do it?
There is also an option at the Android Studio settings to change any Lint error to Lint warning, but I never test that. I usually turn to the gradle solution.
The option is located at Settings > Inspections > Android Lint. For easy find open Settings and at the search (located at the top) type Lint translation there you can change the translation options appear at the left from errors to warnings.
An other option if your error strings never going to be translated is to add at your XML string files tools:ignore="MissingTranslation" either at the root item or at each non-translatable string.
Simple way to solve this Error
Just add following Code To do add "disable 'MissingTranslation'" to your build.gradle file as shown below:
...
android {
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
}
...
OR You can also Add this:
android {
buildTypes {
release {
lintOptions {
disable 'MissingTranslation'
}
}
}
}
You could try to open "Translations Editor" and set the string "..." as "Unstranlatable".
You also must remove all translations of this string.
FWIW: If you don't plan on supporting other languages, then you don't need to disable the lint checks at all. Sometimes your project setup (or a library you're importing) may have accidentally - or intentionally - included a config to support additional languages by declaring a values- folder for that language like this for instance:
<your project source folder>/main/res/values-ar
This was the case for me so I simply removed the folder. But if you have no control over the offending library then one choice is to disable lint abortOnError as indicated in the accepted answer, or find a way to exclude 'library-imported' folders somehow. For the latter option you can start here
there is many solution but i tried
<string name="hello" translatable="false">hello</string>
It's the ignore attribute of the tools namespace in your strings file, as follows:
<?xml version="1.0" encoding="utf-8"?>
<resources
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="MissingTranslation" >
<!-- your strings here; no need now for the translatable attribute -->
</resources>
and from the Gradle
release {
lintOptions {
disable 'MissingTranslation'
}
}
and
android {
lintOptions {
disable 'MissingTranslation'
}
}
Working
buildTypes {
release {
lintOptions {
checkReleaseBuilds false
abortOnError false
}
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

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