Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set severityOverrides in lintOptions?

I have an Android project defining

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        // Android plugin for gradle
        // http://google.github.io/android-gradle-dsl
        classpath 'com.android.tools.build:gradle:1.5.0'

        // ...

In my app I want to set

android {
    // ...

    lintOptions {
        // http://google.github.io/android-gradle-dsl/1.5/com.android.build.gradle.internal.dsl.LintOptions.html#com.android.build.gradle.internal.dsl.LintOptions:severityOverrides
        severityOverrides {
            ["MissingTranslation": "warning"]
        }

        // ...

but I get the error

Error:(34, 0) Gradle DSL method not found: 'severityOverrides()' Possible causes: The project 'android' may be using a version of Gradle that does not contain the method.

What is the correct way to set severityOverrides?


Versions that did compile but do not have the desired effect on the :app:lintVitalRelease build step:

import com.android.builder.model.LintOptions
// ...
severityOverrides ["MissingTranslation": LintOptions.SEVERITY_WARNING]

and

import com.android.builder.model.LintOptions
// ...
severityOverrides.MissingTranslation = LintOptions.SEVERITY_WARNING
like image 537
Simon Warta Avatar asked Feb 12 '16 10:02

Simon Warta


2 Answers

I would like to share what I'm doing.

Instead of set severityOverrides, you can call one method to each type of flag that you want to set.

lintOptions {
    ignore "RtlEnabled", "RtlHardcoded", "RtlSymmetry" ....
    warning "RtlEnabled", "RtlHardcoded", "RtlSymmetry" ....
    error "RtlEnabled", "RtlHardcoded", "RtlSymmetry" ....
    fatal "RtlEnabled", "RtlHardcoded", "RtlSymmetry" ....
    informational "RtlEnabled", "RtlHardcoded", "RtlSymmetry" ....
}

In your case, you can do:

lintOptions {
    warning "MissingTranslation"
}

I'm not sure if you can manually set severityOverrides since it is a read only property.

So, I think you really must call one of the methods above (error, fatal etc..) to override the property that you want

like image 197
W0rmH0le Avatar answered Nov 14 '22 07:11

W0rmH0le


(Not an answer-answer, but this is what I used as an equivalent replacement when I couldn't get lintOptions.severityOverrides to work)

Drop a lint.xml file with the same configuration at the root of the module.

<?xml version="1.0" encoding="UTF-8" ?>
<lint>
    <issue id="MissingTranslation" severity="warning" />
</lint>

You also get a richer API to tune lint warnings through lint.xml.

like image 36
Chaitanya Pramod Avatar answered Nov 14 '22 06:11

Chaitanya Pramod