Ignore R.java files in Find results

后端 未结 6 1743
花落未央
花落未央 2020-12-05 06:51

When I do a Find in Path (Ctrl+Shift+F), I often get results under \"Usages in Generated Code\" in R.java files. When I\'m searching my code, I want to do just that: search

相关标签:
6条回答
  • 2020-12-05 07:35

    I use "custom scopes" in Android Studio to ignore R.java files. Others had described how to create/save a "shared custom scope" which can later be uploaded to a git repository. I'm just gonna share my custom scope string which:

    • ignores R.java files
    • ignores all *.java files generated by Android Annotations (i.e. *_.java files)
    • includes strings.xml, dimens.xml, styles.xml, attrs.xml, colors.xml files
    • includes all xml files in layout/* path

    file:*java&&!file:R.java&&!file:*_.java||file:*strings.xml||file:*dimes.xml||file:*styles.xml||file:*attrs.xml||file:*colors.xml||file:*layout/*xml&&!file:*build/*xml

    0 讨论(0)
  • 2020-12-05 07:37

    To search multiple modules but ignore R.java, you could use the following mask IF you don't have any other single character file names in your project:

    ☑ File mask(s): ??*.*
    

    i.e. Limit results to filenames with at least 2 characters + any extension.

    0 讨论(0)
  • 2020-12-05 07:37

    If you're using Android Studio, a simple way of achieving this is to set the Scope to be Directory (rather than Whole Project) and set this directory to be your src folder - since R.java appears under build/generated it won't appear in results there.

    0 讨论(0)
  • 2020-12-05 07:50

    You could just avoid all the generated files from your project, as Mike Evans suggest in this tweet

    You just need add a scope excluding the pattern mentioned:

    0 讨论(0)
  • 2020-12-05 07:54

    Android Studio (like its progenitor IntelliJ) allows you to define a custom scope to help you exclude intermediates files when searching.

    ]1

    Here are the steps I use to set this up:

    1. Bring up Find in Path dialog (Ctrl+Shift+F on my machine).
    2. In the Scope area, select the Custom radio button. Then tap the "..." button on the right side of the dropdown. This brings up the Scopes dialog.
    3. Click the "+" button on the left side of the Scopes dialog, which will bring up the Add New Scope dialog. Name it "ExcludeIntermediates".
    4. In the Pattern field, paste in the following pattern and click OK:

      !file:*intermediates*/&&!file:*generated*/
      

    This pattern excludes R.java files and other intermediates such as layout files in exploded-aar and AndroidManifest.xml copies in filtered_manifests folders.

    0 讨论(0)
  • 2020-12-05 07:56

    This pattern excludes R.java files and other intermediates such as layout files in exploded-aar and AndroidManifest.xml copies in filtered_manifests folders.

    • ignores R.java files
    • ignores all *.java files generated by Android Annotations (i.e. *_.java files)
    • includes strings.xml, dimens.xml, styles.xml, attrs.xml, colors.xml files
    • includes all xml files in layout/* path

      !file:*intermediates*/&&!file:*generated*/&&file:*java&&!file:R.java&&!file:*_.java||file:*strings.xml||file:*dimes.xml||file:*styles.xml||file:*attrs.xml||file:*colors.xml||file:*layout/*xml&&!file:*build/*xml
      

    Combined from:

    https://stackoverflow.com/a/32238593/1815624

    &

    https://stackoverflow.com/a/32680493/1815624

    0 讨论(0)
提交回复
热议问题