How do I remove directories from Indexing in Android Studio? - 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.

Select the directory in the Project explorer.
CtrlShiftA or ShiftCmdA
Search for Excluded and hit enter.
Careful, I haven't been able to find a way to 're-include' folders back yet.

(optional) Switch to project view if you can't see the folders you want to exclude
Right click the folder you want to exclude
In the contextual menu click "Mark directory as" --> "Excluded"
It should look like this:
(optional) If you want to include a folder, click "Mark directory as" --> "Cancel exclusion"

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.

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

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.

Related

how to include excluded folder in android studio [duplicate]

It's explained how to exclude a directory in Android Studio here. It also has a warning about not knowing how to include it back again. Now I need to do so.
Of-course I can create/import the project again. But I guess there's a better way of doing that. Is there? How?
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/blah/blah/blah/" />
So, Re-including is done as easily as removing the line.
if you right click an excluded directory in the Project View, you can select from the context menu:
Mark directory as → Cancel exclusion
You must delete .iml file then try to sync and it will work fine

How to hide generated dart files in Android Studio

Is it possible to hide generated dart files in Android Studio especially *.g.dart files?
In Project panel, under Options there is a File Nesting Option. I added .chopper.dart; .freezed.dart; .g.dart to .dart parent. This will group related files under the main file.
In Settings panel, open Editor section, and select File Types. Now look for Ignore files and folders field at the bottom. Just include *.g.dart there and you're good to go!

Missing project.gradle in Android View

In Android Studio, project.gradle file is not show when in Android View, but is when in Project view
Android View
Project View
How can I fix this ??
From the Gradle Tool Window in Android Studio (View > Tool Window > Gradle),
Right click on the the project's Gradle config with (root) next to its name.
Click on Ignore Gradle project,
and right click again then click on Unignore Gradle project.
The trigger to this 'buggy' phenomenon actually lies outside your project folder.
Assuming a project name of 'SilverBirch', try this:
(a) Close the project in Android Studio 3.0.1.
(b) Rename your project folder (inside the workspace folder) to 'SilverBitch'
(c) Re-open it via Android Studio (you obviously can't do so using 'recent projects')
(d) You should get a window titled Import Gradle Projects with text that reads: The modules below are not imported from Gradle anymore. Check those to be removed from the ide project too:
(e) Tick the (old) project name and click OK.
(f) At last your 'Android' view shows build.gradle(Project:SilverBitch)
(g) Repeat whole process, renaming back to original.
Alternatively, if you're insane, do this:
Locate the project.dat file AND folder for your project - it will have a path that looks something like this (assuming Windows)
C:\Users\<userid>\.AndroidStudio3.0\system\gradle\Projects\5be1ee38\project.dat
[The system-generated hex-string container name will vary, but the file is always project.dat]
The first line of this file references the 'missing' build.gradle and will clearly identify the owning project.
Delete the file AND its containing folder then re-open the project via Android Studio.
Because googling 'project.dat' yielded nothing, and because I made a rude assumption that this contained only system-generated data, and because I couldn't resist 'seeing what happens' I actually deleted
the entire Projects file [C:\Users\<userid>\.AndroidStudio3.0\system\gradle\Projects]
So far, so good - no serious side-effects yet! Maybe those plugins needed re-specifying anyway? etc.
Close Android Studio -> Remove project .idea folder -> Open Android Studio -> Open your project. This worked for me!
NOTE: when you remove .idea folder you will also lose project related preferences (such as XML code style for project)
Right Click on "Gradle Scripts"
Click Load/Unload modules
Load unloaded project module
Done
In my case, I found that my project.iml located in project/.idea
So I move it to project/
and change one line like following:
<module fileurl="file://$PROJECT_DIR$/My_Project.iml" filepath="$PROJECT_DIR$/My_Project.iml" />
the old one should look like this:
<module fileurl="file://$PROJECT_DIR$/.idea/My_Project.iml" filepath="$PROJECT_DIR$/.idea/My_Project.iml" />
After that, go back to android studio, every thing seems perfect!
This worked for me:
In your root project folder, open the *.iml file, and make sure that the value in module external.linked.project.id=, the *.iml filename, and the project directory name are all the same.
Now my build.gradle (Project: X) shows.
This worked for me.
Simply go to your AndroidStudioProjects Directory.
Search for your Project
Rename it with some other name
Strat your Android Studio, and then Import Project (Gradle, Eclipse ADT, etc.)
mode. let the Gradle Build Finish.
And that's it.

How to re-include an excluded directory in Android Studio?

It's explained how to exclude a directory in Android Studio here. It also has a warning about not knowing how to include it back again. Now I need to do so.
Of-course I can create/import the project again. But I guess there's a better way of doing that. Is there? How?
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/blah/blah/blah/" />
So, Re-including is done as easily as removing the line.
if you right click an excluded directory in the Project View, you can select from the context menu:
Mark directory as → Cancel exclusion
You must delete .iml file then try to sync and it will work fine

Add an already existing directory to a directory in Solution Explorer

I want to add an already existing directory to a directory in Solution Explorer, but whenever I right-click on the directory and select Add => Existing Item, I can only add individual files, but not directories.
How do I add an already existing directory to a directory inside a Project inside Solution Explorer?
Click the 'Show all files' button at the top of the Solution Explorer and right click the folder desired and select 'include in project'.
Drag and drop the folder from Windows Explorer onto your Visual Studio solution window :)
Source here
or simply copy & paste into solution explorer.
VS 2012 seems to distinguish between 'Solution Folders', which are only folders containing either other solution folders, or containing project folders. The drag-and-drop works (with my settings) only for the project folders, and no for the solution folders.
If I add a new solution folder, nothing happens on the machine. If I drag-and-drop a machine folder to the main Solution, it refuses to accept it. If I drag-and-drop the folder to a Solution Folder, I get an error message saying this cannot be done.
Some other answers are missing an important point: if the folder is not in a project in the solution it is impossible to add the folder
This is the solution:
1) Add a new folder to the sln - it does not care that the folder already exists on the disk because this a virtual folder in the sln
2) Add the file to the folder using "add existing files"
When dealing with a solution level folder that has been removed for some reason, and now needs to be added back, open the .sln file in a text editor like notepad++.
Find your "FolderName" in the section that looks like this...
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NewFolder1", "NewFolder1", "{73ED84FC-F250-4CCC-B267-34CEB67F2883}"
EndProject
Delete from "Project" to "EndProject" ONLY for the specific Project/Folder you're having trouble with.
You may get a message in VS2012 that says your solution has been modified by an external source. Choose the option to "Discard" your changes for the external changes. Lastly, add your solution level folder, and add your project(s) to that folder as existing items, drag/drop them, or copy and paste them, according to your preference.
For those who had a hunch it could be done but weren't able to do it, NOTE: Drag Folder or Files ONTO the name of the Project Name in Solution Explorer in the least
Expand the "Project" item in the menu bar and select "Show All Files". Then locate the folder you wish to add in the Solution Explorer (folders that are not currently included will be light grey with a dotted outline instead of the usual solid icon) right click the desired folder and select "Include in project"
Once finished select "Show All Files" from the Project menu again to return to the regular view.
(This is very similar to Radenko Zec's answer, but does not require the "Show All Files" button to already be present in a toolbar. I would just leave this as a response to his answer, but I don't currently have the reputation to leave comments.)

Resources