The simplest way for Android studio to read Android source code

Time:2022-5-24

The simplest way to read Android source code (convenient, fast and complete)

It is very important for Android developers to read the Android system source code, but most of the time we are only concerned about the source code of the framework layer.

However, a search on the Internet teaches us how to download the Android source code locally through AOSP, compile it, and then import it into as for debugging. This process is a very painful process. First of all, the volume of the source code is very large, the download is very difficult, and the disk space is also very large. Then the compiler must have a linux environment. It takes too much time to compile the source code. Who has experienced this process knows.

In order to solve the above problems, let’s smoothly read the source code of the upper framework layer in as. After compiling the Android 10 source code, I deleted all the source codes we didn’t care about,Only the source code of the framework layer is retainedAnd then remove the large files and useless files. In this way, the volume of the whole package is reduced to 1g, and the number of files is reduced to more than 30000.

We developers only need to download the source code of my project, and then after simple configuration, we can read the framework source code very smoothly on androd studio. There is no problem in jumping, searching and writing comments.

use

  1. takeprojectDownload the code in

  2. Open as and open Android under Android 10 through open an existing project IPR file

  3. Associate the source code only with the local code, and leave only the following two under the dependencies.

    The simplest way for Android studio to read Android source code

    20210606132744.jpg

After successful import, you can have a pleasant look at the source code. The speed is still very fast. If you still feel a little stuck, you can install studio in the as installation directory Turn vmoptions up.

-Xms2048m
-Xmx4049m
-XX:ReservedCodeCacheSize=500m
-XX:+UseG1GC
-XX:SoftRefLRUPolicyMSPerMB=50
-XX:CICompilerCount=3

more

If you need to read the source code of other modules, you can download the whole Android 10 source code, and then copy the corresponding module to the project Android 10 directory and download it in Android The corresponding module removal configuration in IML is deleted. For example, add the packages module and delete the following line.

<excludeFolder url="file://$MODULE_DIR$/packages" />

Android 10 entire source code

Link:https://pan.baidu.com/s/1V-stMpLw3xs9k2Zx7hvv8QPassword: ifq4

If you like to toss, you need to compile the source code of the whole system and debug and run the whole system. You can refer to thisConstruction of Android studio source code development environment, the process is a little complicated.

Compiling the source code is easy to encounter the problem of compilation errors. If you encounter the following problems, you can consider the following solutions

1. Used to initialize environment variables

soruce build/envsetup.sh  

2. Generate idegen Jar file

This may fail to generate. If the generation fails, you can use the following link to generate the idea Download the jar locally, and then download the idea Copy jar to out / host / Linux x86 / framework / idegen Jar, and then execute the following command
Link:https://pan.baidu.com/s/17lfmVAs8HRrsk5hbyzkNjAPassword: 2gbx

mmm development/tools/idegen/  
  1. Source code root directory generation file Android IPR (project related settings), Android IML (module related configuration)
./development/tools/idegen/idegen.sh
  1. After generating the source code, you can open android.com through as IPR’s gone, ⚠️ Note that importing the entire Android source code will be very catchy. Unless necessary, it is recommended to import only the source code you need. Related import configuration, in Android In IML, it can be passed as neededexcludeFolderOn Android Remove unnecessary modules from the IML file. The configuration in my project is as follows.
<excludeFolder url="file://$MODULE_DIR$/.repo"/>
   <excludeFolder url="file://$MODULE_DIR$/abi"/>
   <excludeFolder url="file://$MODULE_DIR$/frameworks/base/docs"/>
   <excludeFolder url="file://$MODULE_DIR$/art"/>
   <excludeFolder url="file://$MODULE_DIR$/bionic"/>
   <excludeFolder url="file://$MODULE_DIR$/bootable"/>
   <excludeFolder url="file://$MODULE_DIR$/build"/>
   <excludeFolder url="file://$MODULE_DIR$/cts"/>
   <excludeFolder url="file://$MODULE_DIR$/dalvik"/>
   <excludeFolder url="file://$MODULE_DIR$/developers"/>
   <excludeFolder url="file://$MODULE_DIR$/development"/>
   <excludeFolder url="file://$MODULE_DIR$/device"/>
   <excludeFolder url="file://$MODULE_DIR$/docs"/>
   <excludeFolder url="file://$MODULE_DIR$/external"/>
   <excludeFolder url="file://$MODULE_DIR$/hardware"/>
   <excludeFolder url="file://$MODULE_DIR$/kernel-3.18"/>
   <excludeFolder url="file://$MODULE_DIR$/libcore"/>
   <excludeFolder url="file://$MODULE_DIR$/libnativehelper"/>
   <excludeFolder url="file://$MODULE_DIR$/ndk"/>
   <excludeFolder url="file://$MODULE_DIR$/out"/>
   <excludeFolder url="file://$MODULE_DIR$/pdk"/>
   <excludeFolder url="file://$MODULE_DIR$/platform_testing"/>
   <excludeFolder url="file://$MODULE_DIR$/prebuilts"/>
   <excludeFolder url="file://$MODULE_DIR$/rc_projects"/>
   <excludeFolder url="file://$MODULE_DIR$/sdk"/>
   <excludeFolder url="file://$MODULE_DIR$/system"/>
   <excludeFolder url="file://$MODULE_DIR$/tools"/>
   <excludeFolder url="file://$MODULE_DIR$/trusty"/>
   <excludeFolder url="file://$MODULE_DIR$/vendor"/>
   //Note that the configuration of these removal files above is placed on the < / content > flag
   </content>

Project address:https://github.com/AndroidBBQ/android10

If this article can help you, please order a star!