preface

Series of articles:

Android Studio associated with Android SDK source code (Windows&Mac)

Although you can create an Android App by starting an Activity, it doesn’t seem to require any special skills. However, Android is a huge, systematic project, and there are various compatibility issues. In order to be able to quickly locate the problem, but also in order to learn some excellent coding ideas, often need to locate the Android system source view. This article shares some common ways to view Android source code. Through this article, you will learn:

1, two ways to view the source code locally 2, several ways to view the source code online 3, summary

1, two ways to view the source code locally

(a)Android Studio associated source code

search

Using Activity. Java as an example, search source code in Android Studio:






Android Studio with Android SDK source code (Windows&Mac)

The advantages and disadvantages

advantages

1, because it is downloaded to local, so the search speed is fast. 2. No need to switch out of Android Studio. 3, debugging can also interrupt the point.

Disadvantages such as searching for “Bitmap”:

Further down, there is no C/C++ function corresponding to the “native vecreate “method.

Such as search “AMS” again: ActivityManagerService. Java

(2) download the source code to the local

search

Although Android Studio can download and associate source code with it, it does not download complete source code packages, such as the lack of JNI mapping files, the lack of AIDL files, etc. Download frameworks/base/core/ as an example:





Note: The tool to view the source code here is “Sublime Text”.

The advantages and disadvantages

advantages

Compared to Android Studio’s built-in view of the source code, download to the local source code is more complete.

disadvantages

Indexing and linking between source codes is not very smart due to the use of separate tools to view the source code. Sublime Text, for example, can create “CTags”, but the linking is not as precise as Android Studio.

Download the source code please see: download the official system source code tutorial

2, several ways to view the source code online

The first two ways to view the source code premise is to download the source code to the local, and we know that the Android system source code is complex and complex, taking up local space, and also involves different versions of the source code is different. If we only look at the source code and do not modify the compiled source code, the online source code viewing method is more suitable for our needs. Here are some of the main ways to view source code online:

(a) Android Ref

Android Ref is the most classic way to view things, and it has a long standing. Address: androidxref.com/

Homepage:

As you can see, the index of source code for different versions of the system is listed on the left, using Android 9 as an example:

The search results are as follows:

disadvantages

1. The latest version the site supports is Android 9. 2, foreign websites, although the domestic can also access (no need to climb the wall), but the speed is sometimes slower.

(2) the aosp opersys

Address: aosp.opersys.com/

Homepage:

The current available source versions of the system are listed at the top (Android 11 is not available), using Android 10 as an example:

As you can see, the search interface is similar to Android XRef, with the addition of a Type that specifies the Type of file to search for:

Other operations are similar and will not be detailed here.

disadvantages

1, the website is also a foreign website, sometimes slower. 2, Android 11 source code cannot be accessed (2021-5-30).

(iii)Android Chinese Community

Foreign website speed is limited, the domestic website of course smooth matchless, Android Chinese community built to view the source of the website. Website: www.androidos.net.cn/sourcecode

Homepage:

Take Android 10 as an example:

The advantages and disadvantages

While access speed is no longer a bottleneck, the site’s biggest drawback is that indexes such as methods and classes cannot jump.

(4) Android opengrok

Now you need to find websites that are fast and can support indexing. Address: android-opengrok.bangnimang.net/

Homepage:

The site provides the Opengrok index of Android source code mirror, domestic access without worrying about speed. Take Android 11 as an example:

(4) Official participation of Google

Address: cs.android.com/

Homepage:

Using Android 11 as an example, search activity.java:

To search for all references to the member variable mWindowManager, just click on it. All references to the member variable in activity.java are displayed below. The experience is similar to looking at the source code in Android Studio. It’s nice to look up and jump around, making it much easier to read and understand the logic of the source code (much easier than Android XRef in this respect). And this is a Google product, the source code is up to date, version branch classification is more detailed, more complete.

disadvantages

Need to climb the wall.

3, summarize

The above lists several ways to view the source code from local and online respectively. Personal recommendations are as follows:

1, if there is a wall condition, the first push: cs.android.com/ 2, no wall condition, recommend: The source code is waiting, the waiting is simple. If www.androidos.net.cn/sourcecode 4, simply look at the source code at ordinary times, recommend Android Studio associated source code

If you have a better way to view the Android system source, please feel free to share in the comments section, thanks!

If you like, please like, pay attention to your encouragement is my motivation to move forward

Continue to update, with me step by step system, in-depth study of Android/Java