The easiest way to read Android source code (easy, fast, complete)

It is important for Android developers to read the source code of the Android system, but many times we only care about the source code of the framework layer.

But the Internet search is all about how to download the Android source code through AOSP to the local, and then compile, and then import to AS for debugging. This process is a very painful process, first of all the source code is very large, very difficult to download, and takes up a lot of disk space. To compile, you must have a Linux environment. Even when compiled, the import process can be a time-consuming process due to the amount of source code. This process who has experienced who knows.

To solve the above problem, let us be able to read the source code on the framework layer in AS silky. I in the Android10 source code compilation is completed, we do not care about the source code all deleted, only to keep the framework layer of source code, and then on the large files, useless files to remove. This reduces the overall package size to less than 1G and the number of files to more than 30,000.

We developers just need to download the source code from my project, and then after a simple configuration, it is very smooth to read the FrameWork source code on Androd Studio, jump, search, write comments and so on is no problem. 😄 😄

use

  1. Download the code from the project

  2. Open AS and Open the android.ipr file under Android 10 by opening an Existing Project

  3. Associate the source only locally, leaving only the following two under dependecies.

After the successful import, you can happily see the source code, the speed is very fast, if you feel there is still a bit of slow, you can AS installation directory studio. Vmoptions to expand some.

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

More and more

If you need to read the source code of other modules, you can download the entire Source code of Android10, and then copy the corresponding module to the project Android10 directory, and delete the corresponding module removal configuration in Android.iml. For example, add the packages module and remove the line below.

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

Android10 entire source code

Link: Password :ifq4

If there is like to toss, need to compile the entire system source code, and debug running the entire system. You can refer to this AndroidStudio source code development environment to build, the process is a little complex.

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

1. Used to initialize environment variables

soruce build/envsetup.sh  
Copy the code

2. Generate the idegen.jar file

Jar to out/host/linux-x86/framework/idegen.jar, and then run the following command: password :2gbx

mmm development/tools/idegen/  
Copy the code
  1. Android.iml (module related configuration), android.iml(module related configuration)
./development/tools/idegen/idegen.sh
Copy the code
  1. After generating the source code, you can open android.ipr via AS, ⚠️ Note that importing the entire Android source code is very slow, unless necessary, or it is recommended to import only the part of the source code you need. Related import configuration can be passed in Android. iml as neededexcludeFolderRemove unwanted modules from the android.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:// code_module_dircode/vendor "/>Copy the code

Project address: github.com/AndroidBBQ/…

If this article can help you, please click star! 🙏 🙏 🙏