Android system development to quickly find code (how to find code in a folder)

Many times for those who are new to Android system development, for example, if they pre-set an APK and know the APK package name but don’t know the specific code location, they need to find the code. However, the Android system code is very large, so how to quickly and accurately query the code is a problem.

I have only explored some methods so far. If there are more effective methods, I can add them.

1. Android Studio comes with full text, full folder, full module, etc. search

Ctrl+Shift+F search function, if this key does not take effect, it may need to be set.

You can try the Ctrl+shift+R replacement function first

You can set the search method by selectingIn Project/Module/Directory/Scope

If you are an APP developer, this is a very useful method, but if you are developing on Android system, you will find the limitations of this function, because it needs to load the project before you can use this function.

2.Visual Studio Code search function

The advantage of VSCode compared with AS is that it can be searched without loading. However, the disadvantage is that it is not as fast as searching for codes after AS is loaded, and there may even be unfiltered places left.

Open VSCode and you will see the search interface on the left

3.Python script search

You can check this function on Baidu, but since I don’t know python, I have never used it. It may be roughly a python statement to traverse the text of the folder. If there is a file that meets the requirements, the path of the file is listed.

4. Search using find command under Linux system

Because most Android system development will have a Linx system, the find command can be used, and it is efficient and relatively faster. This is what I recently discovered and the method I like to use. (Usually searched together with AS and VSCode)

The terminal command is as follows, first cd to the path you want to search:

find . | xargs grep -ri "Activity" -l

The above command is to search the text of Activity in the directory. Explain the command:

  1. find .: This part of the command is used to find files in the current directory (represented by .) and its subdirectories. The basic syntax of the find command is find [搜索路径] [匹配条件] [操作].

  2. |: This is the pipe character, passing the output of the find command to the next command.

  3. xargs: This command is used to pass the output of the previous command as a parameter to the following command. Here, it passes the output of the find command to the following grep command.

  4. grep: Used to search for a specified text pattern in a file. Here, grep -ri "csdn.net" -l means:

    • -r: Search subdirectories recursively.
    • -i: Ignore case.
    • -l: Only list file names containing matching patterns without displaying the specific content of the match.

Some other commonly usedfindcommand usages include:

按文件名查找:
find /path/to/search -name "filename"
按类型查找:
find /path/to/search -type f  # 查找普通文件
find /path/to/search -type d  # 查找目录
按大小查找:
find /path/to/search -size +10M  # 查找大于10MB的文件
find /path/to/search -size -1G   # 查找小于1GB的文件
按时间查找:
find /path/to/search -mtime -7  # 查找在过去7天内修改过的文件

Guess you like

Origin blog.csdn.net/m0_59558544/article/details/134336116