How can I find all hard coded strings in my project in Android Studio
AndroidInternationalizationAndroid StudioAndroid Problem Overview
I need to find and extract all hard coded strings in my project in Android Studio (beta) 0.84. I need a static analysis tool like Find Bugs do this for me in one shot and allow me to step through each message and extract the string to resource files. Even better would be if the entire process is automated.
In Android Studio (beta) 0.84 the File / Setting /FindBugs-IDEA shows I18N as an option under Reporting tab. But I just cannot figure out how to make it work.
Thanks for any suggestions.
Android Solutions
Solution 1 - Android
As @Maor Hadad and other upvotes suggested me : I convert my comment in an answer, so :
Since Android Studio 1.2.2, there is a new option in
"Analyse > Run inspection By Name" => "Hardcoded strings".
I used it and it seems quite more reliable with current version than "hardcoded text" (that checks only xml files).
Seen here link
Solution 2 - Android
Go to "Analyze > Run Inspection By Name...", and type "Hardcoded text". Run that one against your whole project, and you should get an inspection results panel that will show the hardcoded text instances.
You can also go to Android Studio > Preferences > Inspections > Hardcoded text and specify exactly how it runs, and what (if any) special cases are excluded from inspection.
Solution 3 - Android
For Windows platform, The best way I found is this:
You can use this shortcut Ctrl
Alt
Shift
I
and search for,
> Hardcoded Text
in the search bar.
You can select appropriate module in which you want to search Hardcoded strings and it will give you the list of all Strings together.
Solution 4 - Android
What worked fine for me was searching on the whole project using regex:
android:text="[a-z]
To find inside those kotlin/java class:
[.]text = "[a-z]
[.]setText("
don't forget to tap on the .* blue button at the very end of this image above
Solution 5 - Android
If you just want to find all the hard coded strings in all the layout files only, you can do so very quickly by running -
vinayak@vinayak-osx:layout $ grep -n "android:text=\"" * | grep -v "@string"
Notes -
grep
can't be used on windows- First
cd
to project'slayout
dir - kcoppock answer is great, but it takes too much time
Solution 6 - Android
Use Ctrl + Shift + F combination for Windows to search everywhere, it shows preview also.
Use Ctrl + F combination for Windows to search in current file.
Use Shift + Shift (Double Shift) combination for Windows to search Project File of Project.
May be unavailable for older versions.