27

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!

Mike Miller
  • 3,368
  • 5
  • 36
  • 49
  • This question has a better answer here: http://stackoverflow.com/questions/29682656/how-do-i-write-a-custom-search-filter-to-weed-out-r-java-files – Ky - Aug 14 '15 at 20:53
  • Possible duplicate of [How do I write a custom search filter to weed out R.java files?](http://stackoverflow.com/questions/29682656/how-do-i-write-a-custom-search-filter-to-weed-out-r-java-files) – CrandellWS Mar 07 '17 at 18:40
  • 1
    @CrandellWS This question is older than that question. – twenk11k Mar 11 '19 at 12:35
  • ok so I noted the other way on that one... thanks @twenk11k – CrandellWS Mar 12 '19 at 17:09

6 Answers6

38

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.

Jo Jo
  • 7,245
  • 5
  • 34
  • 49
  • 3
    Amazing! It's the answer I've been looking for, it's the most correct answer for someone who does Ctrl+Shift+F a lot of times in the day. – Henrique de Sousa Sep 14 '15 at 13:10
  • Correct answer, but a bit outdated. Now Android Studio has a bit different UI so this answer anyway helped me to find Scope button in "Find in path" window. – oxied Oct 10 '18 at 09:05
5

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

Community
  • 1
  • 1
CrandellWS
  • 2,708
  • 5
  • 49
  • 111
4

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.

Pete
  • 424
  • 4
  • 14
2

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.

Mete
  • 5,495
  • 4
  • 32
  • 40
  • Thanks for the answer! This works well for projects containing only one module. Is there a way to search across all the src folders in a project's multiple modules with this method? – Mike Miller Mar 30 '15 at 23:44
  • Not that I'm aware of unfortunately! If we could use regex or signify "not filename" in the file masks I suppose it would be easy, but that doesn't seem to be possible – Mete Mar 31 '15 at 01:18
2

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

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:

enter image description here

cesards
  • 15,882
  • 11
  • 70
  • 65