Tar_Tw45
Tar_Tw45

Reputation: 3222

Android Studio : Exclude files in build folder from search result

I have an Android Studio project in which I have multiple modules, each of those module depending on a share module. And let's say that this share module has an xml file call sample.xml

When I search to open file with Navigate -> Files... and type "sample.xml", I'll get

  1. Share/src/main/res/values/sample.xml
  2. ModuleA/build/intermediates/exploded-arr/.../res/values/sample.xml
  3. ModuleB/build/intermediates/exploded-arr/.../res/values/sample.xml
  4. ModuleC/build/intermediates/exploded-arr/.../res/values/sample.xml
  5. ModuleD/build/intermediates/exploded-arr/.../res/values/sample.xml ...

Since the files in build folder are generated and we shouldn't edit them, there is no reason why I want to include them in my search result. Is there anyway I can exclude them?

Upvotes: 92

Views: 29440

Answers (9)

Synthesis
Synthesis

Reputation: 524

For Kotlin Multiplatform (KMP) project, none of the solutions mentioning build worked, I ended up using this scope to exclude generated resources from Find:

!file[AppName.composeApp.commonMain]:*generated/resources*/&&!file:*.cvr

My guess is the issue here is due to the long filenames in KMP, maybe AS only goes only a couple of levels deeper recursively or the name is truncated at the start due to being to long.

Bottom line is, use the last few folders of files you want to exclude, not the build folder that is 6 levels higher up until this issue is fixed.

Upvotes: 0

3c71
3c71

Reputation: 4511

EDIT November 3rd 2024:

It appears they fixed it in Android Studio at some point in time.

Running "Android Studio Iguana | 2023.2.1 Patch 2" searches dont look in build folders anymore, be it CTRL+SHIFT+F or CTRL+SHIFT+N.

Not sure which version actually fixed it, but that one does have the fix.

Answer from April 15th 2015:

To put it simply, and to actually exclude build paths from your search, you need to follow Frank's answer point 1 and 2, then because there's no suitable scope that actually exclude the build folder, simply do this:

Inside the "Find in Path" dialog (CTRL+SHIFT+F):

  1. tap the ... to configure a scope
  2. click the + button, choose local scope
  3. give your new scope a name
  4. enter !file:build//* in the pattern
  5. tap OK and test your new scope

enter image description here If you further want to have a scope for a single module, create a scope for your module (including recursively your module path), then add this at the beginning of your pattern:

!file:build//*&&

For example, a scope for 2 modules:

!file:build//*&&file[MODULE1_DIRECTORY_NAME]:*/||file[MODULE2_DIRECTORY_NAME]:*/

Only got the full answer reading Frank's answer and post #7 from issue reported here: http://code.google.com/p/android/issues/detail?id=61488

Upvotes: 86

miguel
miguel

Reputation: 16580

None of the patterns in these answers worked for me. This one did: !file:*/build/intermediates//*

Upvotes: 1

yoAlex5
yoAlex5

Reputation: 34175

You can use exclude pattern like

!file:build//*&&

[How to add a new pattern follow and skip tests pattern]
[Skip generated files pattern]

Upvotes: 0

Tomas
Tomas

Reputation: 4861

To exclude all build folders from all modules use this pattern:

!file:*build*/

If you want exclude also all libraries, simply use this pattern:

!file:*build*/&&!lib:*..*

Detailed description:

  1. In the Find window click on the Scope tab, then on three dots button:

enter image description here

  1. Plus button -> Local -> Enter name

enter image description here

  1. Add the desired pattern:

Search scopes

  1. Save and enjoy!

Upvotes: 12

Martino
Martino

Reputation: 261

Android Studio -> Appearance & Behavior -> Scopes -> + -> add scope -> local -> set a custom name & set Pattern

!file:*intermediates*/&&!file:*generated*/&&!file:R.java

enter image description here

Upvotes: 26

Nilzor
Nilzor

Reputation: 18573

This problem seems to be fixed in later versions of Android Studio, but should it reoccur or you have a special folder setup:

You need to modify the exclusion list through gradle with the help of the idea plugin

Example:

apply plugin: 'idea'

idea.module {
    excludeDirs += file('build/')
}

Then run task ideaModule to regenerate the .iml file with the exclusion line described in Corwin's answer

Upvotes: 8

Corwin
Corwin

Reputation: 101

Had the same issue. Found that these 'build' folders were marked as sourceFolder in the module's .iml file.

Removing all such entries fixed the problem

<sourceFolder url="file://$MODULE_DIR$/build/..." ..../>

Upvotes: 10

Frank
Frank

Reputation: 12300

You can create a Custom Scope which defines the set files that you want to search and allows you to exclude those that you do not want to search.

  1. CTRL+SHIFT+F to present the Find in Path dialog.
  2. Under Scope select Custom
  3. If one of the Scopes that are present in the drop down list does not restrict the file search according to your needs you can create your own Custom Scope. To do this click on the ... button.
  4. Then Click on the + button and select Local
  5. In the pane on the right you can Include and Exclude individual files and Recursively include or exclude all files beneath a folder.

You can then use your Custom Scope to constrain the files that are searched when you do Find in Path.

Upvotes: 15

Related Questions