Questions tagged [android-lint]

Android Lint is a tool in ADT which scans Android project sources for potential bugs.

Android Lint is a tool in which scans project sources for potential bugs. It is available both as a command line tool, as well as integrated with .

Here are some examples of the types of errors that it looks for:

  • Missing translations (and unused translations)
  • Layout performance problems (all the issues the old layoutopt tool used to find, and more)
  • Unused resources
  • Inconsistent array sizes (when arrays are defined in multiple configurations)
  • Accessibility and internationalization problems (hardcoded strings, missing contentDescription, etc)
  • Icon problems (like missing densities, duplicate icons, wrong sizes, etc)
  • Usability problems (like not specifying an input type on a text field)
  • Manifest errors

and many more.

336 questions
13
votes
3 answers

Android - set all lint warnings as errors except for certain ones

I am trying to make my continuous integration fail the build when new lint warnings that aren't in the lint-baseline.xml file are introduced. I want to have all lint warnings treated as errors (so the build is aborted), but I'd like a way to specify…
starkej2
  • 11,391
  • 6
  • 35
  • 41
13
votes
1 answer

Explain ClickableViewAccessibility

Concerning the SO swipe code, Android lint gave the warning OnSwipeTouchListener#onTouch should call View#performClick when a click is detected [ClickableViewAccessibility] In the description of the warning, it says: If a View that overrides…
serv-inc
  • 35,772
  • 9
  • 166
  • 188
12
votes
1 answer

SuppressWarnings for: Boolean method 'methodName' is always inverted

The list of the most common SuppressWarnings annotations is so long and non-intuitive, that I am lost to find a correct annotation for warning Boolean method 'methodName' is always inverted I don't want to change the method to return a negative…
Ωmega
  • 42,614
  • 34
  • 134
  • 203
12
votes
3 answers

Lint: "Newer Library Versions Available" when using variables

I have a project with 3 sub-projects. I want the 3 sub-projects to use the same dependencies versions so I factored all the versions in the root build.gradle: allprojects { ext.versions = [ supportLibVersion: '26.1.0', …
mbonnin
  • 6,893
  • 3
  • 39
  • 55
12
votes
1 answer

How to make Grade release build fail using Lint Option StopShip?

I've read a lot about the StopShip Android Lint Check and Gradle support for…
acrespo
  • 1,134
  • 1
  • 10
  • 33
12
votes
2 answers

Lint complains about not translated gcm_defaultSenderId string

I've followed the tutorial https://developers.google.com/cloud-messaging/android/client. It works - I'm able to send and receive notifications. But when I try to build release app, Android Lint complains: Error: "gcm_defaultSenderId" is not…
12
votes
3 answers

Resolving resource values in custom lint rule

I have a large Android codebase and I am writing a custom lint rule that checks whether the values of certain attributes fall within a given range. For example, I have this component:
Mike Laren
  • 8,028
  • 17
  • 51
  • 70
11
votes
1 answer

In-line annotations give syntax errors

I'm loving the new Lint API checks of ADT rev 17, but the new API Correctness Check has got me stumped. I have the following line of code: listView.setOverScrollMode(OVER_SCROLL_NEVER); Lint is reporting on this line: Call requires API level 9…
Paul Lammertsma
  • 37,593
  • 16
  • 136
  • 187
11
votes
1 answer

Lint is giving error if I use java.lang.Iterable#forEach in android code

In my android code (Kotlin) I am using forEach method of java iterable. mandatoryViews.forEach { view -> // my code here } Below is my sdk config in build.gradle (app): minSdkVersion 23 targetSdkVersion 30 Now my code builds fine. I also tried…
Nitin Verma
  • 485
  • 4
  • 19
11
votes
1 answer

How to suppress spellcheck on a string constant in Android Kotlin?

Android Lint picks up the string constant in this code sample as a spelling error on "dWQGSCDx". According to the docs I should use @SupressLint("Typos") to suppress it but that doesn't achieve that. I see others have suggested using…
Ollie C
  • 28,313
  • 34
  • 134
  • 217
11
votes
2 answers

@IntDef annotation and return value from other's code that cannot be annotated or how to temporarily disable annotation from affecting the code?

I am using IntDef from Android Support annotation in my code (but my question is wider in scope so please keep reading :) like this: public class UiLockMode { @IntDef({DEFAULT, NONE, VISIBLE, TRANSPARENT}) @Retention(RetentionPolicy.SOURCE) …
Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
10
votes
1 answer

Unboxing may produce Null Pointer Exception after checking if key exists in Map

Android Studio gives the warning: Unboxing of 'idCollisonMap.get(currentId)' may produce 'NullPointerException' even though I am checking if the key exists before I perform the Map.get(). Am I actually in danger of running into a null pointer…
Kenny Sexton
  • 301
  • 4
  • 14
10
votes
3 answers

Should I use RecyclerView.VERTICAL instead of LinearLayoutManager.VERTICAL?

Running ./gradlew lint reports me an error which is confusing: 39: Must be one of: RecyclerView.HORIZONTAL, RecyclerView.VERTICAL In the source code: 38 LinearLayoutManager linearLayoutManager = new LinearLayoutManager(rootView.getContext()); …
John
  • 1,139
  • 3
  • 16
  • 33
10
votes
2 answers

How to apply @IntRange() support annotation to Kotlin property setter

I have been trying to find out how to apply @IntRange(from = 1) to my Kotlin property. After several failed attempts I finally just created the class I wanted in Java and converted it to Kotlin inside Android Studio. Here is my Java class: import…
Adam
  • 2,167
  • 5
  • 19
  • 33
10
votes
1 answer

Writing custom lint warning to check for custom annotation

I have written the following annotation: import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import…
Adam
  • 2,167
  • 5
  • 19
  • 33