Android source code compilation

Source: Internet
Author: User
Tags uncompress

/**
Version: 1.0
Date: 2009-03-18
Author: hkjinzhao
Remarks: initial version
*/
/**
Version: 1.1
Date: 2009-03-27
Author: hkjinzhao
Note: add the make SDK and modify some content.
*/

This compilation process mainly refer to the official documentation (http://source.android.com/download) and relevant online materials (such as http://blog.csdn.net/liaoshengjiong/archive/2009/03/04/3957749.aspx)

Compiling environment: ubuntu8.10

1. install some environments
Sudo apt-Get install build-essential
Sudo apt-Get install make
Sudo apt-Get install gcc
Sudo apt-Get install g ++
Sudo apt-Get install libc6-dev
 
Sudo apt-Get Install patch
Sudo apt-Get install texinfo
Sudo apt-Get install libncurses-Dev
 
Sudo apt-Get install Git-core GnuPG
Sudo apt-Get install flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl
Sudo apt-Get install ncurses-Dev
Sudo apt-Get install zlib1g-dev
Sudo apt-Get install valgrind
Sudo apt-Get install python2.5

Install the Java environment
Sudo apt-Get install sun-java6-jre sun-java6-plugin sun-java6-fonts sun-java6-jdk

Note: The official documentation said that if the problem with sun-java6-jdk, you have to use sun-java5-jdk. Tests showed that if only make (make does not include make SDK), it is no problem to use sun-java6-jdk. The Make SDK has a problem. Strictly speaking, there is a problem with make doc. It requires the javadoc version 1.5.
Therefore, we 'd better install the sun-java6-jdk after installing the sun-java5-jdk, or just install the sun-java5-jdk. Here, both sun-java6-jdkand sun-java5-jdkare installed, and only javadoc.1.gz and javadoc are modified. Because only these two are used by the make SDK. In this case, except that the javadoc tool uses version 1.5, all other tools use version 1.6:
Sudo apt-Get install sun-java5-jdk
Modify the link of javadoc
CD/etc/alternatives
Sudo RM javadoc.1.gz
Sudo ln-S/usr/lib/JVM/Java-1.5.0-sun/man/Man1/javadoc.1.gz javadoc.1.gz
Sudo RM javadoc
Sudo ln-S/usr/lib/JVM/Java-1.5.0-sun/bin/javadoc

2. Set Environment Variables
Vim ~ /. Bashrc
Add or integrate the PATH variable in. bashrc as follows:

# Java program development/running environment variables
Java_home =/usr/lib/JVM/Java-6-sun
Jre_home =$ {java_home}/JRE
Export android_java_home = $ java_home
Export classpath =. :$ {java_home}/lib: $ jre_home/lib: $ classpath
Export java_path =$ {java_home}/bin: $ {jre_home}/bin
Export java_home;
Export jre_home;
Export classpath;
Home_bin = ~ /Bin/
Export path =$ {path }:$ {java_path }:$ {jre_path }:: {home_bin };
# Echo $ path;

Finally, synchronize these changes:
Source ~ /. Bashrc

3. Install repo (used to update the android source code)
Create ~ /Bin directory, used to store the repo program, as follows:
$ Cd ~
$ Mkdir Bin
And add it to the environment variable path. It has been added to step 1.
Download the repo script and make it executable:
$ Curl http://android.git.kernel.org/repo> ~ /Bin/Repo
$ Chmod A + x ~ /Bin/Repo

4. Download and update the android source code
We recommend that you do not use Repo for download (Android Source Code exceeds 1 GB, which is very slow). Download http://www.androidin.com/bbs/pub/cupcake.tar.gzfrom the internet. The extracted cupcake file also contains the. Repo folder. You can use repo sync to update the cupcake code:
Tar-xvf cupcake.tar.gz

Repo sync (the update is slow and takes 3 hours)

5. Compile the android source code and obtain ~ /Project/Android/cupcake/out directory
Go to the android source code directory:
Make
This process takes a long time (more than two hours)

6. Run and compile android on the simulator

Android SDK emulator program in the android-sdk-linux_x86-1.0_r2/tools/, emulator is to load some image, the default load android-sdk-linux_x86-1.0_r2/tools/lib/images under the kernel-qemu (kernel) ramdisk. IMG system. IMG userdata. IMG

After compiling Android, emulator ~ /Project/Android/cupcake/out/host/linux-x86/bin, ramdisk. IMG system. IMG userdata. img in ~ /Project/Android/cupcake/out/target/product/generic
Cd ~ /Project/Android/cupcake/out/host/linux-x86/bin

Add environment variable
Vim ~ /. Bashrc
Add environment variables in. bashrc as follows:
# Java program development/running environment variables
Export android_product_out = ~ /Project/Android/cupcake2/out/target/product/generic
Android_product_out_bin = ~ /Project/Android/cupcake2/out/host/linux-x86/bin
Export path =$ {path }:$ {android_product_out_bin };

Finally, synchronize these changes:
Source ~ /. Bashrc

Emulator-image system. IMG-data userdata. IMG-ramdisk. img
After entering the android desktop, it means the operation is successful.
Out/host/linux-x86/bin generates many useful tools (including all the tools for Android SDK/tools), so, the android SDK path in eclipse can be specified to the out/host/linux-x86/bin for development.

7. Compile Linux Kernel
When you directly make the android source code, there is no make Linux kernel. Therefore, it is running the simulator, so you do not need to compile Linux kernel. If you want to migrate the value to Android, or add or delete a driver, you need to compile the Linux Kernel
Linux Kernel compilation will be introduced in future articles.

8. Compilation Module
An application in android can be compiled separately. After compilation, system. IMG must be regenerated.
Run the following command in the source code directory:
. Build/envsetup. Sh (. There is a space behind it)
There are more commands:
-Croot: Changes directory to the top of the tree.
-M: makes from the top of the tree.
-Mm: builds all of the modules in the current directory.
-Mmm: builds all of the modules in the supplied directories.
-Cgrep: greps on all local C/C ++ files.
-Jgrep: greps on all local java files.
-Resgrep: greps on all local Res/*. XML files.
-Godir: Go to the directory containing a file.
You can add-help to view usage
We can use Mmm to compile the module of the specified directory, for example, compile the contact:
Mmm packages/apps/contacts/
Generate two files after editing:
Out/target/product/generic/data/APP/contactstests.apk
Out/target/product/generic/system/APP/contacts.apk
You can use make Snod to regenerate system. IMG.
Run the simulator again.

9. Compile the SDK
Directly executing make does not include the make SDK. Make SDK is used to generate the SDK, so that we can use the SDK synchronized with the source code to develop android.

1) Modify/frameworks/base/include/utils/asset. h
Change 'uncompress _ data_max = 1*1024*1024 'to 'uncompress _ data_max = 2*1024*1024'
The reason is that the eclipse compilation project requires a buffer greater than 1.3m.

2) Compile ADT.
Note that we first execute 2) and then 3 ). Because the generated SDK is cleared when you execute./build_server.sh.
With the new source code, the ADT debugging tool has to be generated by itself. The steps are as follows:
Go to the development/tools/Eclipse/scripts directory of cupcake source code and execute:
Export eclipse_home = Your eclipse path
./Build_server.sh you want to put the ADT path

3) execute make SDK.
Note that the javadoc version needed here is 1.5, so you need to install the sun-java5-jdk at the same time in step 1
Make SDK
Compilation is slow. The compiled SDK is stored in the out/host/linux-x86/SDK/directory with android-sdk_eng.xxx_linux-x86.zip and android-sdk_eng.xxx_linux-x86. Android-sdk_eng.xxx_linux-x86 is the SDK directory
In fact, when using the mmm command to compile the module, the same will clear the SDK output file, so it is best to move the android-sdk_eng.xxx_linux-x86 out

4) Selection of environment variables and Android tools
Currently, Android tools include:
A. the SDK we downloaded from the Internet (many Android tools and IMG images under lib/images)
B. the SDK compiled using make SDK (there are also many Android tools in tools, and IMG images in lib/images)
C. The out directory compiled with make (there are also many Android tools in tools, and IMG images in lib/images)
So what tools should we use and IMG?
First, we will not use the option tool and IMG, because it is generally old and the source code is not synchronized. The test showed that if option B and IMG were used, the android simulator window would become smaller (maybe skin could not be loaded), but the tool and IMG with option C would not have this problem.
Some Android tools depend on Android. Jar (such as Android). Therefore, we use option B tool (SDK) and Option C IMG in eclipse. In fact, we can see from emulator-help-Build-images that android_product_out points to the IMG directory of the C option.
However, in addition to the tool and IMG using option A, sdcard cannot be loaded using B or C simulators. The reason is unclear.

5) install and configure ADT
For more information about how to install and configure ADT, see the official documentation.

6) Create an android Virtual Device
The compiled SDK does not have AVD (Android Virtual Device). You can view it using the android tool:
Android list
Output:
Available Android targets:
[1] Android 1.5
API level: 3
Skins: HVGA-P, QVGA-L, HVGA-L, hvga (default), QVGA-P
Available Android Virtual Devices:
Indicates no AVD. If there is no AVD, errors will occur during eclipse compilation (failed to find a AVD compatible with target 'android 1.5 '. Launch aborted .)
Create AVD:
Android create AVD-T 1-C ~ /Sdcard. IMG-N myavd
You can use Android-help to view the usage of the preceding Command Options. There are some options in the creation, the default is enough
Run the android LIST command to view the location where AVD is stored.
In the future, the-AVD myavd or @ myavd option will be added to every running of emulator. Here, eclipse will debug the program in the emulator you open.

Note:
In this way, the SDK and ADT are generated and integrated into eclipse according to the official documents.
Create a new Android project and try your own SDK.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.