Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore R.java files in Find results

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 my code. Not files generated by my code.

Is it possible to get the find dialog to not show any R.java files in the results? The only results I want are those under "Found Occurrences"

Thank you!

like image 709
Mike Miller Avatar asked Apr 09 '14 21:04

Mike Miller


4 Answers

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.

like image 123
Jo Jo Avatar answered Nov 12 '22 01:11

Jo Jo


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

like image 31
CrandellWS Avatar answered Nov 12 '22 02:11

CrandellWS


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.

like image 4
Pete Avatar answered Nov 12 '22 03:11

Pete


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.

like image 2
Mete Avatar answered Nov 12 '22 01:11

Mete