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.

5 Answers 5

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.

4
  • 2
    A dirty way to re-include the folder is to edit the parent .iml file and remove the corresponding excludeFolder entry. Oct 18, 2017 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. Nov 12, 2017 at 14:50
  • @JoshuaPinter Yes, you're right. I've just posted a new solution that I've used successfully. Nov 12, 2017 at 22:35
  • @DavidBurström Good stuff. Same solution I found for it: stackoverflow.com/a/47244842/293280 Nov 13, 2017 at 3: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
1
  • 2
    This is simplest solution worked for me. Just make sure to reopen project after excluding directory Jul 26, 2020 at 12:02
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.

4
  • When you say "anymore", which versions are involved then? Sep 21, 2019 at 16:56
  • 3
    excludeDirs += works, but excludeDirs.add does not work. This applies to Android Studio 3.5: stackoverflow.com/questions/58033717/…
    – Mike76
    Sep 21, 2019 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, 2019 at 17:36
  • how to exclude a particular file type from indexing? Apr 12, 2022 at 7: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.

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.