Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Snackbar] Gradle lint task fails inconsistently: WrongConstant #504

Closed
erikhuizinga opened this issue Aug 6, 2019 · 23 comments
Closed

Comments

@erikhuizinga
Copy link

erikhuizinga commented Aug 6, 2019

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

@erikhuizinga erikhuizinga changed the title [Component name] Short description of issue [Snackbar] Gradle lint task fails inconsitently: WrongConstant Aug 6, 2019
@erikhuizinga erikhuizinga changed the title [Snackbar] Gradle lint task fails inconsitently: WrongConstant [Snackbar] Gradle lint task fails inconsistently: WrongConstant Aug 6, 2019
@khaykov
Copy link

khaykov commented Oct 9, 2019

I'm experiencing this one with beta01

@sagarchavda
Copy link

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

@erikhuizinga
Copy link
Author

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

@vincent-paing
Copy link

vincent-paing commented Dec 12, 2019

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()
                                                 ~~~~~~~~~~~~~~~~~~~~

@erikhuizinga
Copy link
Author

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

@npike
Copy link

npike commented Mar 18, 2020

Seems to not be an issue on alpha05.

@kevinvillalobosGL
Copy link

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.

@romaopedro
Copy link

@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
Copy link

@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.

@romaopedro
Copy link

romaopedro commented Apr 15, 2020

@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.

@dsn5ft
Copy link
Contributor

dsn5ft commented Apr 21, 2020

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

@romaopedro
Copy link

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

@azaricstefan
Copy link

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.

@josephyanks
Copy link

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

Target: 29, Gradle 4.0.1

@chiel99
Copy link

chiel99 commented Sep 2, 2020

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

@ataraxus
Copy link

ataraxus commented Sep 16, 2020

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

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

@LokmaneKrizou
Copy link

Any updates to resolve this issue?

@nmhung
Copy link

nmhung commented Apr 19, 2021

Same here.
Looking forward to updating on this issue.

@drchen
Copy link
Contributor

drchen commented Feb 7, 2022

This seems only happening on a certain gradle version?

We removed @IntDef from the @duration definition in 3cf23e4

Can you help check if this also solves the lint issue reported here?

@erikhuizinga
Copy link
Author

I can't reproduce this in my old project, back when I had this issue and reported it. That project had too many dependencies back then that are now obsolete, which makes it impossible to build it at all. Currently the project depends on Material 1.4.0 and that doesn't seem to have this issue. I tried 20 builds without suppressing the lint error and they all passed.

@drchen
Copy link
Contributor

drchen commented Feb 9, 2022

Thank you so much for the confirmation. If that's the case I guess the issue was solved even before the commit I linked. : )

@drchen drchen closed this as completed Feb 9, 2022
@azaricstefan
Copy link

I confirm that issue is not present in 1.5.0 version. Hope this info helps someone.

@drchen
Copy link
Contributor

drchen commented Feb 10, 2022

@azaricstefan Thanks for your confirmation! That's helpful. : )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests