How can I find all RELEVANT hard coded strings in Android Studio?

后端 未结 2 1212
伪装坚强ぢ
伪装坚强ぢ 2021-01-06 13:14

A few flavors of this question have been asked before, but I don\'t understand how the answers to them are satisfactory for large projects.

My goal here is to find a

相关标签:
2条回答
  • 2021-01-06 13:30

    Just add //NON-NLS after your log line to suppress the warning.

    NGMCLogger.i(TAG, "This log does not need translation"); //NON-NLS
    
    0 讨论(0)
  • 2021-01-06 13:36

    With version 1.3 of Android Studio, after running "Hardcoded text" inspection by name, it does indeed catch lots of non-issues, such as parameters to Log methods.

    However, the right panel of the inspection result window contains information about the rule, along with some "problem resolution" options. One of those options will be "Annotate parameter..." or "Annotate class...". These options create entries in an annotations.xml file that tells the inspection rule to ignore those parameters or classes.

    With this, subsequent runs of the inspection won't flag those calls. So after you do it for a couple of code files, you will probably hit most of the exceptions and it will cut down the number of results for the whole project.

    Here is an example of the XML that is generated in the annotations.xml file:

    <root>
      <item name='android.content.Intent Intent(java.lang.String) 0'>
        <annotation name='org.jetbrains.annotations.NonNls'/>
      </item>
      <item name='android.content.Intent android.content.Intent putExtra(java.lang.String, boolean) 0'>
        <annotation name='org.jetbrains.annotations.NonNls'/>
      </item>
      <item name='android.content.Intent android.content.Intent putExtra(java.lang.String, int) 0'>
        <annotation name='org.jetbrains.annotations.NonNls'/>
      </item>
      <item name='android.content.Intent android.content.Intent setAction(java.lang.String) 0'>
        <annotation name='org.jetbrains.annotations.NonNls'/>
      </item>
    </root>
    
    0 讨论(0)
提交回复
热议问题