(#) Inconsistencies in array element counts !!! WARNING: Inconsistencies in array element counts This is a warning. Id : `InconsistentArrays` Summary : Inconsistencies in array element counts Severity : Warning Category : Correctness Platform : Android Vendor : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 Since : Initial Affects : Resource files Editing : This check runs on the fly in the IDE editor Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ArraySizeDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ArraySizeDetectorTest.kt) Copyright Year : 2011 When an array is translated in a different locale, it should normally have the same number of elements as the original array. When adding or removing elements to an array, it is easy to forget to update all the locales, and this lint warning finds inconsistencies like these. Note however that there may be cases where you really want to declare a different number of array items in each configuration (for example where the array represents available options, and those options differ for different layout orientations and so on), so use your own judgment to decide if this is really an error. You can suppress this error type if it finds false errors in your project. (##) Example Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/values/arrays.xml:3:Warning: Array security_questions has an inconsistent number of items (3 in values-nl-rNL/arrays.xml, 4 in values-cs/arrays.xml) [InconsistentArrays] <string-array name="security_questions"> ^ res/values/arrays.xml:10:Warning: Array signal_strength has an inconsistent number of items (5 in values/arrays.xml, 6 in values-land/arrays.xml) [InconsistentArrays] <array name="signal_strength"> ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here are the relevant source files: `res/values/arrays.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers <resources> <!-- Choices for Locations in SetupWizard's Set Time and Data Activity --> <string-array name="security_questions"> <item>Favorite food?</item> <item>City of birth?</item> <item>Best childhood friend\'s name?</item> <item>Highschool name?</item> </string-array> <array name="signal_strength"> <item>@drawable/ic_setups_signal_0</item> <item>@drawable/ic_setups_signal_1</item> <item>@drawable/ic_setups_signal_2</item> <item>@drawable/ic_setups_signal_3</item> <item>@drawable/ic_setups_signal_4</item> </array> </resources> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `res/values-cs/arrays.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers <resources xmlns:android="http://schemas.android.com/apk/res/android" xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> <string-array name="security_questions"> <item>"Oblíbené jídlo?"</item> <item>"Město narození."</item> <item>"Jméno nejlepšího kamaráda z dětství?"</item> <item>"Název střední školy"</item> </string-array> </resources> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `res/values-land/arrays.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers <resources> <array name="signal_strength"> <item>@drawable/ic_setups_signal_0</item> <item>@drawable/ic_setups_signal_1</item> <item>@drawable/ic_setups_signal_2</item> <item>@drawable/ic_setups_signal_3</item> <item>@drawable/ic_setups_signal_4</item> <item>@drawable/extra</item> </array> </resources> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `res/values-nl-rNL/arrays.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers <resources xmlns:android="http://schemas.android.com/apk/res/android" xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> <string-array name="security_questions"> <item>"Favoriete eten?"</item> <item>"Geboorteplaats?"</item> <item>"Naam van middelbare school?"</item> </string-array> </resources> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `res/values-es/strings.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers <resources xmlns:android="http://schemas.android.com/apk/res/android" xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> <string name="home_title">"Casa"</string> <string name="show_all_apps">"Todo"</string> <string name="menu_wallpaper">"Papel tapiz"</string> <string name="menu_search">"Búsqueda"</string> <!-- no translation found for menu_settings (1769059051084007158) --> <skip /> <string name="wallpaper_instructions">"Puntee en la imagen para establecer papel tapiz vertical"</string> <string-array name="security_questions"> <item>"Comida favorita"</item> <item>"Ciudad de nacimiento"</item> <item>"Nombre de tu mejor amigo/a de la infancia"</item> <item>"Nombre de tu colegio"</item> </string-array> </resources> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ArraySizeDetectorTest.kt) for the unit tests for this check to see additional scenarios. The above example was automatically extracted from the first unit test found for this lint check, `ArraySizeDetector.testArraySizes`. To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=192708. (##) Suppressing You can suppress false positives using one of the following mechanisms: * Adding the suppression attribute `tools:ignore="InconsistentArrays"` on the problematic XML element (or one of its enclosing elements). You may also need to add the following namespace declaration on the root element in the XML file if it's not already there: `xmlns:tools="http://schemas.android.com/tools"`. ```xml <?xml version="1.0" encoding="UTF-8"?> <resources xmlns:tools="http://schemas.android.com/tools"> ... <array tools:ignore="InconsistentArrays" .../> ... </resources> ``` * Using a special `lint.xml` file in the source tree which turns off the check in that folder and any sub folder. A simple file might look like this: ```xml <?xml version="1.0" encoding="UTF-8"?> <lint> <issue id="InconsistentArrays" severity="ignore" /> </lint> ``` Instead of `ignore` you can also change the severity here, for example from `error` to `warning`. You can find additional documentation on how to filter issues by path, regular expression and so on [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). * In Gradle projects, using the DSL syntax to configure lint. For example, you can use something like ```gradle lintOptions { disable 'InconsistentArrays' } ``` In Android projects this should be nested inside an `android { }` block. * For manual invocations of `lint`, using the `--ignore` flag: ``` $ lint --ignore InconsistentArrays ...` ``` * Last, but not least, using baselines, as discussed [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html).