Because the "deep understanding of Android Volume One" and "deep understanding of Android Volume Two" is no longer published, and the dissemination of knowledge should not be due to the problem of paper media, so I will be in the OSC blog full-text forward the full content of the two books.
1th Development Environment Deployment
The main contents of this chapter:
A brief introduction to the architecture of the book, the build environment, and how to debug the Systemserver process with eclipse.
1.1 System Architecture
So far, the latest version of the Android system is 4.0.3. As the book is about to be finalized, there are rumors in the industry that Android 4.0. Version 4 has been released for large vendors. The speed with which the Android system was launched was a surprise to many developers. Of course, the speed of launch is so fast that some are commercially considered. In any case, the overall architecture of the Android system has remained relatively stable over the course of its evolution. Figure 1-1 is an android system architecture diagram.
Figure 1-1 Android System architecture
It is believed that the vast majority of readers are familiar with the contents of Figure 1-1 or similar charts. Here, we will not repeat it.
As the second volume of "in-depth understanding of Android", this book will take the content of "in-depth understanding of Android: Volume I" (hereafter referred to as "Volume I"), but the focus of this book is shifted from the native layer framework to the Java layer framework. This book covers the content shown in 1-2.
Figure 1-2 What this book covers
From Figure 1-2, the reader can see that most of the content in this book is about service. That's true. Because the core of the Android Java Layer Framework is these service. It is no exaggeration to say that these service support the entire Java layer of the world's operation. The reader can refer to figure 3-1 of the 3rd chapter for an overview of the service in the framework.
1.2 Building the development environment
This section discusses the Android 4.0 source code download, the Eclipse development environment, and how to debug the Systemserver process.
1.2.1 Download Source code
After Android 2.3, Google officially recommends using a 64-bit operating system to compile the source code. Therefore, the reader should first install the 64-bit OS. I recommend the operating system is Ubuntu 10.04 x86-64 version. In addition, readers should not be free to upgrade Ubuntu, because the high version of the Ubuntu version of the GCC is too high, will lead to compile Android source code problems.
In fact, 32-bit Ubuntu can also compile Android 2.3 Android system, but it is quite troublesome, and there is no technical content. The author recommends that the reader follow the official request to do it.
I'm not going to talk too much about the steps of the Android source download, because this is a process that requires the reader to do the work, and it is much more efficient to watch a computer screen operation than to enter a string of strings after reading a book.
For this reason, the author provides an official document to the reader, the address is http://source.android.com/source/downloading.html. This page has detailed code download steps, and the reader can do a hands-on experiment simply by performing a simple copy/paste operation. The page is shown in Figure 1-3.
Figure 1-3 Android code download page
Note that readers should choose to download the Android 4.0.1 code. Although the latest version of Android 4.0.3 is not much changed from the version number, the actual code has changed significantly.
In addition, due to the poor network environment, if the reader found that this chapter is not available to connect, from the author's blog link to download the source code and tools, blog address is: http://blog.csdn.net/innost/article/details/7525205.
1.2.2 Compiling source code
1. Deploying the JDK
Android 2.3 and later versions of code compile all need to use JDK1.6, so the first thing to do is to download JDK1.6. The download URL is http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase6-419409.html. The file downloaded by the author is Jdk-6u27-linux-x64.bin. Put it in a directory, such as put it in the/mnt/hgfs/e directory, and then execute it in this directory:
./Jdk-6u27-linux-x64.bin #执行这个文件
The effect of this command is actually decompression. The extracted results are in the/mnt/hgfs/e/jdk1.6.0_27 directory. After you have the JDK, you also need to set up the ~/.BASHRC file. At the end of the file, add a few lines of statements that are shown in 1-4:
Figure 1-4 Java Environment deployment
Once the system is re-logged, the Java environment is added to the system.
2. Compiling the source code
The procedure for compiling the source code is very simple. We also detail the compilation method in Volume I. However, this book requires the reader to compile the entire system first, with the following steps:
· Executes the source build/envsetup.sh command. The command will be imported into the Android compilation environment.
· Enter Choosecombo and execute, which is a function defined in envsetup.sh. In the process of execution, choose Release, Generic, Eng respectively. The final screen output is shown in 1-5.
Figure 1-5 Compilation settings
· Execute the make command to compile the entire system. The compile time is determined by the machine configuration. The compilation time of the author's 4-core 4GB machine is about 2 hours.
1.2.3 using Eclipse Debug Systemserver
This section describes how to use Eclipse to debug the core process Systemserver of the Android Java framework.
1. Configure Eclipse
The first thing to do is download the Android SDK. For http://developer.android.com/sdk/index.html. In the Linux environment, this site is shown in 1-6.
Figure 1-6 androidsdk download page
The author downloads the SDK on the Linux system. The location after decompression is under/thunderst/disk/anroid/android-sdk-linux_x86.
Then, to install the ADT plug-in for Eclipse (Android development Tools), follow these steps.
· Click the Eclipse menu bar Help->install New software, enter Android adt:https://dl-ssl.google.com/android/eclipse/, and then install all of the components and restart Eclipse.
· Click the Eclipse menu bar preferences->android, and in the Right SDK location, enter the directory you just extracted from the SDK, that is, the author set the/thunderst/disk/anroid/ Android-sdk-linux_x86, as shown in the final result 1-7.
Figure 1-7 SDK Installation
· Click the Eclipse menu bar window->android SDK Manager, which pops up a dialog box, shown in 1-8.
Figure 1-8 Android SDK Manager dialog box
In Figure 1-8, select the SDK documentation, image files, development packages, and so on, where tools and corresponding versions are downloaded. Eligible readers can download all the content and tools for Android 4.0.3 and 4.0.
2. Using the coffee Bytes Java plugin
Coffee Bytesjava is a plug-in for eclipse that folds code and is much more powerful than the code folding that comes with eclipse. For large-segment code research, the role of the plug-in can not be. The installation and configuration steps for this plugin are as follows:
· Click the Eclipse menu bar Help->install New software, enter Http://eclipse.realjenius.com/update-site in the pop-up dialog box, and choose to install the plugin.
· Click the Eclipse menu bar window->preference, enter folding in the upper-left corner to search, as shown in result 1-9.
Figure 1-9 Coffee Bytes Java plug-in configuration
In the dialog shown in Figure 1-9, open the enablefolding option First, and then select Coffeebytes Java folding from the Select Foldingto use box. Figure 1-9 The check box in the lower right section is used to configure the code folding function for this plug-in. The reader may wish to configure it as shown in Figure 1-9. Use the plugin as shown in 1-10.
|
If you don't care about the else if branch, you can fold the code. |
Figure 1-10 Example of using Coffee Bytes java plugin
As you can see from figure 1-10, after using the plug-in, basically all the branches in the code can be collapsed, which will help developers focus on the branches they care about.
3. Import Android Source code
Note that this step must compile a complete Android source code before it can be implemented, the steps are as follows:
· Copy Android source directory/development/ide/eclipse/.classpath to Android source root directory.
· Open the. classpath file under the Andriod source root directory. This file is intended for use by Eclipse, where the path to each module in the source directory is saved. Since we only care about the framework-related modules, it is possible to comment out some directories that are not the framework from the file. At the same time, remove unnecessary modules can also speed up the Android source code import speed. Figure 1-11 shows some of the contents of the file.
Figure 1-11.classpath File section file contents
In addition, some unnecessary modules will cause subsequent Android source compilation failures in Eclipse. The author shares a. classpath file that readers can download from http://download.csdn.net/detail/innost/4247578 and use directly.
Click the Eclipse menu bar New->java Project, which pops up the dialog box shown in 1-12. Set location to the path of Android4.0 source.
Figure 1-12 Importing Android source code
Because the Android 4.0 source files are many, the import process will continue for a long time, about 10 minutes or so.
Note Before importing the source code, be sure to remove the Eclipse's automatic compilation options (via the menu bar project->buildproject automatically settings). In addition, the source code after the completion of the reader must not clean this project. Cleanup will delete the files generated by the previous source compilation, resulting in subsequent recompilation of the Android system.
4. Create and run the emulator
Click the Eclipse menu bar WINDOW->AVD Manager, create emulator, 1-13.
Figure 1-13 Simulator creation
Once the simulator is created, you can start it.
5. Debug Systemserver
The steps to debug systemserver are as follows:
· First compile Android source code project. There will be a lot of warnings during the compilation process. If there is an error, most of the reason is that the. classpath file contains the modules that are not needed. The reader can do the appropriate processing according to Eclipse's prompts. I configured a few machines are basically a configuration on the success.
· Right-click on the Android source project, click Debug as->debug configurations, pop up the dialog box shown in 1-14, and then find the Remotejava application column from the left.
Figure 1-14 Debug Configuration box
· Click the New button in the black box in Figure 1-14, and then set the dialog box by the contents of the black box in Figure 1-15.
Figure 1-15 Remote Java application Configuration
As shown in Figure 1-15, you need to select the remote debug port number to 8600,host type localhost. 8600 is the debug port number for the systemserver process. Once eclipse is connected to the port, the Systemserver can be debugged through the JDWP protocol.
· After the configuration is complete, click the Debug button in the lower right corner of figure 1-15 to start debugging the Systemserver.
Figure 1-16 shows the author debugging the startactivity process.
Figure 1-16 Systemserver debugging
1.3 Summary of this chapter
This chapter on the Android system and source building, and how to use Eclipse debugging Systemserver and so on to do the relevant introduction, I believe the reader is now impatient? Start our source code journey now!
Android Development Environment Deployment