7

The Open File window in Android Studio, Command+Shift+O, will search all directories by default, including the node_modules directory. This forces you to have to go through endless common files, like AndroidManifest.xml, before finding the one in your root directory.

I noticed that in the my_project.iml file there is an excludeFolder tag but any edits I make to the my_project.iml file get overwritten the next time I rebuild the project.

How do I exclude the node_modules directory permanently from coming up in the Open File window?

This is on Android Studio 3.0.

Joshua Pinter
  • 45,245
  • 23
  • 243
  • 245
  • Possible duplicate of [How do I remove directories from Indexing in Android Studio?](https://stackoverflow.com/questions/26767923/how-do-i-remove-directories-from-indexing-in-android-studio) – nhoxbypass Nov 12 '17 at 06:53
  • If you are trying to open up react-native android project you can just add the android folder to Android Studio and not the complete react-native project. This way you just see the related files with android in your Android Studio project structure. – bennygenel Nov 12 '17 at 08:32
  • @bennygenel You're definitely right for most cases, however, we've integrated React Native to an existing Android app so there is no `android` directory. We'll probably change that later when we add iOS and Windows support. – Joshua Pinter Nov 12 '17 at 14:49

1 Answers1

6

Add excludeDirs in your build.gradle file.

As per Nilzor's solution, the right way to do this is by adding the following to your root build.gradle file:

apply plugin: 'idea'

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

Now, rebuild your project and check your my_project.iml file. You'll see the new excludeFolder entry:

<content url="file://$MODULE_DIR$">
  <excludeFolder url="file://$MODULE_DIR$/.gradle" />
  <excludeFolder url="file://$MODULE_DIR$/node_modules" />
</content>
Joshua Pinter
  • 45,245
  • 23
  • 243
  • 245