Material-components-android: [Snackbar] Gradle lint task fails inconsistently: WrongConstant

Created on 6 Aug 2019  Â·  16Comments  Â·  Source: material-components/material-components-android

Description:

./gradlew lint would fail on Material v1.1.0-alpha07 and before, and Android Studio would show a lint error for Snackbar.make(view, "Replace with your own action", BaseTransientBottomBar.LENGTH_LONG) with a WrongConstant error. (Snackbar.LENGTH_LONG should be used instead.)

On v1.1.0-alpha08 and v1.1.0-alpha09 ./gradlew lint fails sometimes (about half the time) and the Android Studio lint error is no longer shown. This also happens on v1.2.0-alpha03.

Expected behavior:

The Gradle lint task fails or succeeds consistently and Android Studio's linter reflects this success/failure.

Source code:

Snackbar.make(view, "Replace with your own action", BaseTransientBottomBar.LENGTH_LONG)

Android API version:

28

Material Library version:

OK: v1.1.0-alpha-07 and earlier
Not OK: v1.1.0-alpha08, v1.1.0-alpha09, v1.2.0-alpha03

Device:

N/A

bug

Most helpful comment

+1 same issue
material version: 1.1.0, 1.2.0
API: 29
Gradle 4.0.1

Workaround:
lintOptions {
disable 'WrongConstant'
}
thx: @azaricstefan

All 16 comments

I'm experiencing this one with beta01

@erikhuizinga How can I prevent this issue for now until not fixed?

@sam4444 don't use a version greater than v1.1.0-alpha-07.

Still happening in 1.2.0 alpha-01

Error: Must be one of: BaseTransientBottomBar.LENGTH_INDEFINITE, BaseTransientBottomBar.LENGTH_SHORT, BaseTransientBottomBar.LENGTH_LONG or value must be ≥ 1 (was 0) [WrongConstant]
      Snackbar.make(requireView(), errorMessage, Snackbar.LENGTH_LONG).show()
                                                 ~~~~~~~~~~~~~~~~~~~~

This is still an issue with Material v1.2.0-alpha03.

Seems to not be an issue on alpha05.

This seems to be happening during certain builds for alpha05 and alpha06. I found a workaround for these versions, by changing the Build Variant and forcing the project to re-index everything and then run the lint (or assemble) task again.

@kevinvillalobosGL how did you fix the problem? I already did: Refresh Gradle Dependencies, Reimport Gradle Project, Clear cache and restart, delete build folder, clear project, rebuild project. The problem persists.

@kevinvillalobosGL how did you fix the problem? I already did: Refresh Gradle Dependencies, Reimport Gradle Project, Clear cache and restart, delete build folder, clear project, rebuild project. The problem persists.

The issue persists, especially on our CI, changing the Build Variant is only a workaround to force the the re-index and clean build, but still could happen. So we decided to disable the abortOnError:

android { lintOptions { abortOnError false } }

We do have a custom Lint check on our UnitTest so we are keeping this disabled until we get a working solution from the Material Library.

@kevinvillalobosGL I forgot to mention, I changed the BuildVariant but didn't work either.

Using the abortOnError, it will work, thank you.

Meanwhile, I'm using a different workaround. I add this annotation to the method with the crashing code.
@SuppressLint("WrongConstant")

The suppress can be added to the lint.xml file, but in my case, I use the Snackbar.LENGTH_INFINITE in just one place in the project.

Hello all, what versions of Android Studio and the Android Gradle Plugin are you using to reproduce these errors?

@dsn5ft using AS 3.6.2. Didn't test with 3.6.3 that I've just updated. Gradle plugin 3.6.2.

Issue is still present in material library version 1.3.0* and 1.2.0* (* means all minor versions).

Android API version 29|28
Gradle version: 4.0.1

Solved it by disabling the warning WrongConstant, but this is not good.

Please resolve this issue.

+1 we are also experiencing this issue on v1.2.0

Target: 29, Gradle 4.0.1

+1 same issue
material version: 1.2.0
API: 29
Gradle 4.0.1

+1 same issue
material version: 1.1.0, 1.2.0
API: 29
Gradle 4.0.1

Workaround:
lintOptions {
disable 'WrongConstant'
}
thx: @azaricstefan

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sepehr-alipour picture sepehr-alipour  Â·  3Comments

KelvinPac picture KelvinPac  Â·  3Comments

ataulm picture ataulm  Â·  3Comments

magnusfernandes picture magnusfernandes  Â·  3Comments

gabrielemariotti picture gabrielemariotti  Â·  3Comments