18

Search Everywhere is not working fine in Android Studio 3. When I type anything, it doesn't show up. Take a look at screenshot below, typed AndroidManifest but no result.

If I look for any layout file, it shows file reference in R.layout file.

Searching for a layout file and getting results from R file.

Searching for AndroidManifest and its asking to create a new file :/

EDIT:

Ctrl + Shift + N doesn't work as well.

enter image description here

Tried restarting AS but no luck.

Noman Rafique
  • 3,735
  • 26
  • 29

5 Answers5

33

Go to File -> Invalidate Caches / Restart...

Once you have restarted the search index will be rebuilt.

Victor Rendina
  • 1,130
  • 12
  • 19
  • Working fine for me – Ranjithkumar Apr 20 '19 at 21:22
  • This "solution" is unacceptable! How do you know that you have to do this? Do you do this EVERY TIME YOU DO A SEARCH? I'm going back to using grep--at least it won't give false results. – SMBiggs Feb 07 '21 at 03:41
  • @SMBiggs in the last 5 years of using Android Studio daily I've had to do this maybe twice to rebuild the search index. Your solution below using grep is not an adequate replacement for the search everywhere functionality and doesn't address the OP's question. Perhaps you should file an issue on the Android Studio bug tracker if you are seeing this frequently? – Victor Rendina Feb 10 '21 at 13:41
  • @VictorRendina Not a bad idea. I'll add it to their bugs, thanks for the suggestion. – SMBiggs Feb 11 '21 at 02:37
2

Search in Android Studio is not reliable. Since so much programming really needs searching to work and work EVERY TIME (and since invalidating caches and restarting is NOT AN OPTION for each time you need to search) I have the following old-school but reliable solution:

grep

Make sure your working directory is the base directory of your project. Type:

grep -r 'pattern' .

  • To make it case insensitive, add "-i" to the command.
  • You can add a file pattern with "--include [file_pattern]", such as --include "*.java" or --include "*.xml" to speed things up.
  • You can pipe the results into a file or the less command, where you can then search the search results, ;)

And the best part? It Works!

SMBiggs
  • 11,034
  • 6
  • 68
  • 83
  • Ok... but it still doesn't take me straight to the result, right? Coz often when I search everywhere, I KNOW where the code is!... I'm just too lazy to manually navigate to it... – Karolina Hagegård Sep 05 '22 at 14:03
  • Hehe. Grep won't take you to the code, but it _will_ tell you the file, file location, and the line number. The rest is up to you, unless your editor/IDE can understand grep (and some do I think). – SMBiggs Sep 07 '22 at 21:36
  • Oh, darnit... Well, invalidate caches and restart seems to have done it, anyway. But as you say, that adds a lot of time to your project! (I'm using Android Studio - do you know if it "understands grep" somehow?) – Karolina Hagegård Sep 08 '22 at 07:20
  • Not really something I've played with much. But View->Tool Windows->Terminal (or alt-F12) will get you a nice command line window which should make things a little easier. – SMBiggs Sep 08 '22 at 19:06
2

For me it works neither. The search everywhere function is broken for me, at least, it does not search everywhere (no full text search). I can literally paste a line of code of a file open in android studio, into the search everywhere box and it does not return the file that is open in front of me.

The find in files (ctrl + shift + f) function searches text / source files for the string and gives the expected result.

Harmen
  • 841
  • 8
  • 17
0

Search Everywhere shows "Recent Files" if the files have not been opened recently then they will not show up in search. Open all your files (you can open 10 at a time by selecting and pressing Enter key) and close all. This will index them all in recent files and then you can use search everywhere.

Not sure how time is calculated for "Recency".

A better way to search for file is go to Navigate->File (by this way you can search for any file). You can note the shortcut written next to it (depending on if you are using Mac or Windows).

DragonFire
  • 3,722
  • 2
  • 38
  • 51
0

For me, Searching for a File does not work, but Search Everywhere works. Invalidating Caches does nothing to fix it, and it has nothing to do with Recent Files either. The File Search simply does not work. our project has a very deeply nested file structure, maybe that has something to do with it, but I don't know - search everywhere still works so I doubt it. The only solution I see for now is to use grep.

ibrust
  • 171
  • 1
  • 6