Android Studio View Framework source code

1. Background

The source code of the Android system is huge. Choosing good development tools and methods for development can improve development efficiency. Commonly used development tools include Source Insight, Visual Studio Code, and Android Studio. vscode is suitable for C and C++ code development. Java layer code cannot be jumped. and tips, therefore, it is more convenient to use as to develop code involving the java layer. This article will introduce the as integrated Framework source code development method.

2. Compile ipr

2.1 Configure the compilation environment
//在源码根目录执行以下
source build/envsetup.sh
lunch kona-userdebug  //这里可能不一样,例如 lunch 40 也可以,根据场景选择
2.2 Compile idegen module
mmm development/tools/idegen/  //生成文件 out/host/linux-x86/framework/idegen.jar
2.3 Execute the script to generate ipr and iml files
./development/tools/idegen/idegen.sh

//博主这边执行上面命令后,生成的ipr文件在该目录:/development/tools/idegen/templates/android.ipr
//注:有可能每个人的不一样,可以在源码根目录通过以下命令搜索:find . -name android.ipr

 Copy the generated android.ipr file to the source code root directory

3, general introduced AndroidStudio

Open AS, click File -> Open, and select the android.ipr file copied to the source code root directory earlier. This process is time-consuming.

android.iml file

        The iml file is the file of the idea organization project, which records various record modules, folders and dependency information. Generally speaking, all projects created will have this file. Its essence is a project organization file, which is no different from Maven's pom.xml, gradle's build.gradle, and other files that organize projects and handle dependencies.

Open the android.iml file, we will find that there are many configuration items in this file, mainly class tags:

sourceFolder: Indicates the included file directory. Usually we only need to leave framewrok.

excludeFolder: exclude, as the name suggests, means not to include. We have many directories that we don’t want Studio to take care of, whether it’s indexing or anything else, so we just need to configure these directories in it.

What if you have imported all the projects into Android Studio and want to delete them? In fact, a simple way is to enter the directory Project Structure -> Modules to quickly remove certain modules. The red code Excluded option (which means deleted Directory), we only view the framework module, so the codes of other modules are all set to Excluded, as shown below:

Select the file directory on the left, right-click and select Exclueed. If the directory to be loaded is too large, it will take a long time to load. It is recommended to directly block unused directories.

4. Dealing with slow loading and freezing issues of open android.ipr

4.1 Cancel loading git and use manual code synchronization to sync the code, as shown below:

4.2 2. Increase AS running memory

5. Install Android Studio in Linux and access editing in Window

If the configuration of the window computer is not high, after importing the source code and opening as, the computer will be very stuck. To solve this problem, the blogger introduces another method. 

5.1 Find a Linux server with high configuration

Install the linux version of Android studio in the server and configure the jdk environment

5.2 Install Xmanager in window. The blogger installed Xmanager 7 and used xshell7
5.3 Use xshell to connect to the server on a windows computer, then in Android Studio, cd to the android-studio/bin directory, execute the studio.sh script to open Android Studio, and then import android.ipr

Note: Generally, importing compiled iml files and android.ipr files can cause source code jumps and prompts. When bloggers encounter problems that cannot be achieved, they copy the previously generated jumpable iml files and android.ipr files to The source code directory is fine, provided that the source code and directory are the same. The iml file contains the content path of the entire Android source code, which generally has more than 10,000 lines. If there are dozens of lines, there is usually a problem and there is no way to jump and access.

Guess you like

Origin blog.csdn.net/banzhuantuqiang/article/details/134030243