Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect resource variable typos in Android Studio (ex: "%1$ s")

Android crashes are often caused by a resource containing %1$ s when %1$s was intended.
To my surprise, Android Studio does not show these syntax errors:

enter image description here

↑ The real syntax error above is the %1$ s (makes the app crash), not the ellipsis that Android Studio highlights.

How to check for resource variable typos in Android Studio?
I am looking for the equivalent of lint --check StringFormatInvalid.

Context: Many semi-automatic language translation tools break variables, making apps crash.

What I have tried, does not work:

Android Studio Lint Invalid format string Highlighting level Inspections

like image 756
Nicolas Raoul Avatar asked Jan 13 '16 06:01

Nicolas Raoul


1 Answers

in Intellij it is possible to create custom inspections. I am not sure if it is possible in Android Studio.

Follow the link: https://www.jetbrains.com/idea/help/creating-custom-inspections.html

edit:

after follow the steps in the link you see in the next image my created inspection: enter image description here

In the next image you see the basic configuration of the inspection: enter image description here

In the next two images you see the setting of the variables. Only the used regex is not the ready. You must write it for general variable using (between $ and . is a space): enter image description here enter image description here

like image 161
schlagi123 Avatar answered Nov 03 '22 10:11

schlagi123