gregm
gregm

Reputation: 12169

How do I remove directories from Indexing in Android Studio?

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.

Upvotes: 32

Views: 11458

Answers (6)

Luis E. Fernandez
Luis E. Fernandez

Reputation: 856

Just add the following at project's build.gradle file.

tasks.processResources {
     exclude("**/*")
}

Upvotes: 0

Mert Durukan
Mert Durukan

Reputation: 108

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.

Upvotes: 0

Sourav Kannantha B
Sourav Kannantha B

Reputation: 3299

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

Upvotes: 0

Tea Ghosty
Tea Ghosty

Reputation: 201

  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

Upvotes: 20

David Burstr&#246;m
David Burstr&#246;m

Reputation: 1610

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.

Upvotes: 10

Gautam
Gautam

Reputation: 4026

  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.

Upvotes: 26

Related Questions