28

I have a large project folder that contains many sub projects. Only 4 are part of the Android project, the rest are C code.

However, it appears that Android Studio is indexing ALL of it, which takes a long time.

How do I exclude these other directories from indexing?

There no way to explicitly do it, and the Module Settings only lists the Android projects so I cannot remove the other folders from there.

gregm
  • 12,019
  • 7
  • 56
  • 78

5 Answers5

26
  1. Select the directory in the Project explorer.
  2. CtrlShiftA or ShiftCmdA
  3. Search for Excluded and hit enter.

Careful, I haven't been able to find a way to 're-include' folders back yet.

Gautam
  • 4,006
  • 3
  • 32
  • 37
  • 2
    A dirty way to re-include the folder is to edit the parent .iml file and remove the corresponding excludeFolder entry. – David Burström Oct 18 '17 at 16:18
  • 1
    @DavidBurström Don't the `.iml` files get overwritten by Android Studio on each project build? Pretty sure you'll need to remove it from a `build.gradle` file somewhere, which is where the `excludeFolder` entry gets generated from. – Joshua Pinter Nov 12 '17 at 14:50
  • @JoshuaPinter Yes, you're right. I've just posted a new solution that I've used successfully. – David Burström Nov 12 '17 at 22:35
  • @DavidBurström Good stuff. Same solution I found for it: https://stackoverflow.com/a/47244842/293280 – Joshua Pinter Nov 13 '17 at 03:13
18
  1. (optional) Switch to project view if you can't see the folders you want to exclude
  2. Right click the folder you want to exclude
  3. In the contextual menu click "Mark directory as" --> "Excluded"
    It should look like this: IDE contextual menu
  4. (optional) If you want to include a folder, click "Mark directory as" --> "Cancel exclusion" Other IDE contextual menu
β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83
Tea Ghosty
  • 181
  • 2
  • 4
9

Use the 'idea' plugin to exclude directories. For some reason, it seems the idea configuration is ignored if a subproject is configuring it (and will always exclude the project.buildDir and .gradle folders), but it works if you tell the root project which directories to exclude:

In your root project build.gradle file, do

apply plugin: 'idea'
idea {
  module {
    excludeDirs.add(file('path/to/subproject'))
    excludeDirs.add(file('path/to/othersubproject'))
  }
}

After syncing, you'll notice that the root projects .iml file contains corresponding <excludeFolder> tags, and that Android Studio no longer indexes the directories.

David Burström
  • 1,592
  • 14
  • 14
  • When you say "anymore", which versions are involved then? – David Burström Sep 21 '19 at 16:56
  • 3
    excludeDirs += works, but excludeDirs.add does not work. This applies to Android Studio 3.5: https://stackoverflow.com/questions/58033717/android-studio-how-to-exclude-doc-folder-from-search-and-other-functionality – Mike76 Sep 21 '19 at 17:35
  • This might be a bug of the idea gradle plugin. Does the above snippet still work for you for recent Studio and gradle versions? – Mike76 Sep 21 '19 at 17:36
  • how to exclude a particular file type from indexing? – Vivek Mangal Apr 12 '22 at 07:44
0

In the left side project panel, right click the file you want to exclude from indexing, and then select Mark as Plain Text.

Sourav Kannantha B
  • 2,860
  • 1
  • 11
  • 35
0

As there is no "Mark directory as" menu in Android Studio, I found out that such settings like including and excluding directories are stored in a ".iml" file. Named like "project-name.iml".

A line like bellow is used to exclude a dir:

<excludeFolder url="file://$MODULE_DIR$/src/main/x/" />

So, Re-including is done as easily as removing the line.