Reputation: 153
Android studio lint don't work for a kotlin project. I can't find hardcoded strings. What can be solution for this?
Upvotes: 12
Views: 2020
Reputation: 694
Ah, well actually there's an update. Kotlin IDE does understand org.jetbrains.annotations.PropertyKey 11, but it does not always work. I have had problems if the bundle contains more than one language.
Example:
fun message(@PropertyKey(resourceBundle = "Messages") id: String) =
ResourceBundle.getBundle("Messages").getString(sid) ?: "###$id###"
For more visit:https://developer.android.com/studio/write/lint#src
Upvotes: 0
Reputation: 2860
I suggest using Detekt for static analysis in Kotlin, specifically the string literal duplication.
Upvotes: 0
Reputation: 2305
Do these steps it worked for me
*.kt
or choose kt
from the
drop down.= \"\w+\"
you can see the results now.=\"\w+\"
in case code is not formatted
properly.Upvotes: 2
Reputation: 366
Use Edit/Find/"Find in Path" (shortcut is Cmd+Shift+F on Mac).
Then select the check on "Regex?" at the top of the "Find in Path" window and type \"*\"
in the search input.
Then choose to search in Directory and then select the directory with kotlin files. Search separately in /activities
and in /fragments
(and any other directory where you might have kotlin code).
(To search for raw strings use \"\"\"*\"
.)
Screenshot of "Find in Path" search for strings example
I'm not sure if this is a 100% reliable solution but it worked for me. "Analyse -> Run inspection By Name" then type "Hardcoded strings" does not work for me.
Upvotes: 0