61

Every time I use Search In Path in Android Studio, I end up with generated code being returned as the first section of results.

I usually search for something in *.java,*.xml, and usually investigate the first few results before I realize I'm looking at Generated Code. Is there a way to omit the generated code results from being returned as part of the result list, while still allowing the search to read all of the *.java and *.xml files in my project?

I have a feeling this is something beyond ridiculously simple, but I just can't find the right button to toggle.


In the same vein, is it possible to ignore generated classes when loading files or types? I keep getting the generated MyClass$$ViewInjector classes appearing first in open files, and it's just annoying...

Travis
  • 3,737
  • 1
  • 24
  • 24
  • possible duplicate of [Android Studio : Exclude files in build folder from search result](http://stackoverflow.com/questions/28937468/android-studio-exclude-files-in-build-folder-from-search-result) – jt-gilkeson Jun 26 '15 at 20:48
  • Hear hear! And to always put the generated code at the top, as if that's what most people are searching for! Sigh. – SMBiggs Jan 08 '16 at 22:27
  • @Travis you should really accept the answer... – Henrique de Sousa Oct 27 '16 at 16:14
  • Possible duplicate of [Ignore R.java fies in Find results](http://stackoverflow.com/questions/22973939/ignore-r-java-fies-in-find-results) – CrandellWS Jan 02 '17 at 09:17
  • 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:41

3 Answers3

84

The way I've been doing to ignore generated classes in advanced search is adding !file:*intermediates*/&&!file:*generated*/&&!lib:*..* to a new Custom Scope, like this:

enter image description here

14-October-2015 Update: I have improved the pattern by also excluding the !lib:*..* from the search. Thanks.

Henrique de Sousa
  • 5,727
  • 49
  • 55
  • 2
    @Gazta this configuration is stored in the `.idea/scopes/` folder. In order to set it up across different projects, you'll need to copy that file around. See also [this SO answer.](http://stackoverflow.com/questions/5313946/can-i-share-settings-for-intellij-idea-across-different-projects) – Henrique de Sousa Aug 07 '16 at 17:45
  • there should be a global scope, I hope they add it soon. – Computer's Guy Aug 07 '16 at 19:32
  • Thank you! But databinding files are not excluded. Can you help me? Path: app/build/generated/source/kapt/develDebug/de/XXXXX/YYYY/ZZZZ/databinding/FragmentDownloadBindingImpl.java << not excluded – tzanke Jun 30 '22 at 11:17
  • It should be excluded since its path contains the `generated` string. Can you confirm? – Henrique de Sousa Jul 04 '22 at 18:28
2

I've seen this in IntelliJ, haven't checked in Android Studio. But when you do find in path (via ctrl+shift+F) there's a "File name filter" section in the search popup which has a checkbox called "File masks" which you might be able to filter desired file types.

Vinit Nayak
  • 103
  • 1
  • 9
  • It generates .java files though, so it's not super helpful. It's gotten a lot better as of late, so it's not nearly as annoying as it used to be. Thanks for the suggestion! – Travis Aug 19 '15 at 15:57
1

For me, just to add to the answer, the scope !file:*intermediates*/&&!file:*generated*/&&!file:*build*/&&!lib:*..* worked even better!

Simon
  • 2,643
  • 3
  • 40
  • 61