A few days ago, I switched back to ubuntu11.04 to experience the following unity desktop.
The download of the Android system source code (including the SDK source code) mainly requires the use of the GIT tool. I will take some time to introduce the use of the GIT tool. Here I will briefly describe it when using it.
1. Install git and curl
Command:
$ Sudo apt-Get install Git-core curl
Note:
Curl is a tool for transferring data to or from a server. It supports HTTP, https, FTP, ftps, SCP, SFTP, TFTP, dict, telnet, LDAP, or file protocols. For Web developers HTTP The support for post is of great help to us.
Git is a distributed version control system. Source codeClone it.
2. Install repo
command:
$ Mkdir bin // download the repo script to the local bin folder $ curl http://android.git.kernel.org/repo> ~ /Bin/repo // set the executable permissions for the local repo $ chmod A + x ~ /Bin/repo // temporarily Add the repo to the environment variable to facilitate subsequent execution. $ Export Path = ~ /Bin: $ path
Note:
Repo is a git-based version library management tool that simplifies git usage during Android development. Here, the repo and the official Android project list are used to automatically batch download the entire android project, eliminating the need to download a large amount of manual work for each project.
3. initialize the repo Client
Command:
// Create the directory Android/Android-source to store the downloaded source code $ mkdir Android/Android-source-P // enter the directory $ CD Android/Android-source // get the project list and initialize the directory $ repo init-u git: // android.git.kernel.org/platform/manifest.git
After Initialization is complete, the repo initialized in/home/http://www.cnblogs.com/xx, such:
4. Synchronize the version Library
Command:
$ Repo sync
To put it bluntly, download the latest one from the serverCode.
The next step is a long wait. I still have 10 mbps bandwidth and downloaded it for several hours. If you forget it, you will not post it.
5. Download the source code of a single project
Previously we downloaded the entire android project, including virtual machines, sdks, and ndk. However, for many application developers, it is enough to download the android SDK source code, there is no need to download all the three multi-G source codes.
Therefore, we use the SDK source code as an example to demonstrate how to use git to download a single project (the repo tool is not required for downloading a single project ).
Open webpage Http://android.git.kernel.org/, which includes a large number of androidrelated projects.
The android SDK code is included in the android core framework. The project path is platform/frameworks/base. Git.
Command:
// Go to the previously created Android directory $ CD Android // clone the server base version library and code to the Android-SDK-source directory $ git clone git: // android.git.kernel.org/platform/frameworks/base.git Android-SDK-Source
Wait a moment, about 200 M. After the download is complete, as shown in.
Similarly, you can download any other single project to your local device.
6. Obtain the SDK source code of each version.
For SDK source code of various versions, there are still many people in urgent need on the Internet. I beg for something. Today I am here to introduce some ideas, but I will not download them, after all, the file still has a certain size.
First, we can get the logos of SDK versions in two ways: 1. Branch through branch; 2. Tag through tag.
Let's first look at the results:
// Enter the base version library directory $ CD Android-SDK-source // display all the branches, including remote and local branches. We have not created any branch, all without local branches $ git branch-A // display all tags $ git tag
See the following two figures:
Figure A git branch-
Figure B git tag
From the above two figures, we can see each branch number and tag number, which is the basis for switching the branch and checking the tag. Regarding the differences between the two,
If you only download the file, you do not need to know it for the moment. branch can submit and modify the file. The tag is only an important tag, but you cannot modify the code corresponding to the tag.
We all know that Android 2.3 has started to add NFC, so the NFC directory will also be added in the source code. Based on this, we will switch to the branches before and after 2.3 and compare them.
We use the GIT checkout (Branch) command to check the branches. We check the branches of Version 2.2 and Version 2.3 respectively (switch under the same directory ):
The results are as follows:
Figure A froyo version (android2.2)
Figure B gingerbread version (Version 2.3, ginger pie)
Compared with figure A and Figure B, we find that figure B has an NFC Directory, which means we switched to Version 2.3.
The check-out tag is exactly the same, for example, git check android-sdk-2.1_r1
By switching different branches, we can obtain the SDK source code of all different versions, and the switching speed is still very fast.
7. Link Android. Jar source code
We generally like to download the SDK source code of each version, which is stored in the sources directory of each version, so that the Android. Jar link in the eclipse method can be used. I will not introduce this method much.
Today, I will introduce another method that allows you to easily switch the source code by using only one simple command. Oh, you have thought of it. That's right, you just need to use the previous checkout command to switch.
Right-click attach source in Android. jar of the project and select the Android-SDK-source folder,
After the link is complete, you can view the SDK source code. if the version is inconsistent, you only need to execute git checkout branchname under the Android-SDK-source directory and switch to the corresponding version, you no longer need to find the source code of each version.
Of course, the two methods have their own length. I think it is better to use either of them. I am in a Linux environment, so the latter one will be better.
8. Summary
The source code is a fortune. Sticking to the source code and analyzing the underlying implementation and framework modes is definitely an excellent learning experience and will certainly be of great benefit.
Later, I may analyze the architecture layers of the android source code for you, compile your Android system, and customize Android in depth. The time schedule and details are provided.
However, one of them is certain. I will open a separate topic later to analyze the android source code: 1. Use the source code to describe common things; 2. design pattern, so stay tuned!