Detailed explanation of Android source code compilation

Source: Internet
Author: User
Tags uncompress

This article describes how to set the compiling environment of the Android source code, including the configuration in Linux. It is mainly based on the Android 1.0 environment and hopes to help you understand Android development.

This compilation process mainly refer to the official document http://source.Android.com/download) and online related information such as http://blog.csdn.net/liaoshengjiong/archive/2009/03/04/3957749.aspx)

Compiling environment: Ubuntu8.10

1. install some environments

 
 
  1. sudo apt-get install build-essential  
  2.  sudo apt-get install make  
  3.  sudo apt-get install gcc  
  4.  sudo apt-get install g++  
  5.  sudo apt-get install libc6-dev  
  6.    
  7.  sudo apt-get install patch  
  8.  sudo apt-get install texinfo  
  9.  sudo apt-get install libncurses-dev  
  10.    
  11.  sudo apt-get install git-core gnupg  
  12.  sudo apt-get install flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl  
  13.  sudo apt-get install ncurses-dev   
  14.  sudo apt-get install zlib1g-dev  
  15.  sudo apt-get install valgrind  
  16.  sudo apt-get install python2.5 

Install the java environment

 
 
  1. 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 show that if only makemake 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:

 
 
  1. sudo apt-get install sun-java5-jdk 

Modify the link of javadoc

 
 
  1. cd /etc/alternatives  
  2. sudo rm javadoc.1.gz  
  3. sudo ln -s /usr/lib/jvm/java-1.5.0-sun/man/man1/javadoc.1.gz javadoc.1.gz  
  4. sudo rm javadoc  
  5. sudo ln -s /usr/lib/jvm/java-1.5.0-sun/bin/javadoc javadoc 

2. Set Environment Variables

 
 
  1. vim ~/.bashrc 

Add or integrate the PATH variable in. bashrc as follows:

 
 
  1. # Java program development/running environment variables
  2. JAVA_HOME =/usr/lib/jvm/java-6-sun
  3. JRE_HOME =$ {JAVA_HOME}/jre
  4. Export Android_JAVA_HOME = $ JAVA_HOME
  5. Export CLASSPATH =. :$ {JAVA_HOME}/lib: $ JRE_HOME/lib: $ CLASSPATH
  6. Export JAVA_PATH =$ {JAVA_HOME}/bin: $ {JRE_HOME}/bin
  7. Export JAVA_HOME;
  8. Export JRE_HOME;
  9. Export CLASSPATH;
  10. HOME_BIN = ~ /Bin/
  11. Export PATH =$ {PATH }:$ {JAVA_PATH }:$ {JRE_PATH }:: {HOME_BIN };
  12. # Echo $ PATH;

Finally, synchronize these changes:

 
 
  1. source ~/.bashrc 

3. Install repo to update the Android source code)

Create ~ /Bin directory, used to store the repo program, as follows:

 
 
  1. $ cd ~  
  2. $ 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:

 
 
  1. $ curl http://Android.git.kernel.org/repo >~/bin/repo  
  2. $ chmod a+x ~/bin/repo 

4. Download and update the Android source code

We recommend that you do not use repo to download the Android source code that exceeds 1 GB.) 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:

 
 
  1. tar -xvf  cupcake.tar.gz  

Repo sync updates are 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 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 required 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

 
 
  1. vim ~/.bashrc 

Add environment variables in. bashrc as follows:

 
 
  1. # Java program development/running environment variables
  2. Export Android_PRODUCT_OUT = ~ /Project/Android/cupcake2/out/target/product/generic
  3. Android_PRODUCT_OUT_BIN = ~ /Project/Android/cupcake2/out/host/linux-x86/bin
  4. Export PATH =$ {PATH }:$ {Android_PRODUCT_OUT_BIN };

Finally, synchronize these changes:

 
 
  1. source ~/.bashrc  
  2. emulator -image system.img -data userdata.img -ramdisk 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:

 
 
  1. . Build/envsetup. sh. There is a space behind it)

There are more commands:

 
 
  1. - croot:   Changes directory to the top of the tree.  
  2. - m:       Makes from the top of the tree.  
  3. - mm:      Builds all of the modules in the current directory.  
  4. - mmm:     Builds all of the modules in the supplied directories.  
  5. - cgrep:   Greps on all local C/C++ files.  
  6. - jgrep:   Greps on all local Java files.  
  7. - resgrep: Greps on all local res/*.xml files.  
  8. - 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:

 
 
  1. mmm packages/apps/Contacts/ 

Generate two files after editing:

 
 
  1. out/target/product/generic/data/app/ContactsTests.apk  
  2. out/target/product/generic/system/app/ Contacts.apk 

  • Google CEO talks about Android and Chrome OS
  • Developers are worried about the rapid development of Android
  • Google founder Blin: Chrome OS and Android will be integrated
  • Six Reasons why Android occupies 2010
  • Developer resentment: Android apps are like nightmares

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. There are many Android tools under SDK tools we downloaded from the Internet, and img images under lib/images)

B. There are also many Android tools under the sdk tools compiled using make SDK, and img images under lib/images)

C. There are also many Android tools in out directory tools compiled with make, 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 shows that if the tool and img of Option B are used, the Android simulator window may become smaller because skin cannot be loaded), but the tool and img of Option C do not have this problem.

Some Android tools depend on Android. jar, such as Android). Therefore, we use the tool SDK of Option B in eclipse) and use the img of option C. 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 AVDAndroid Virtual Device). You can view it using the Android tool:

Android list

Output:

 
 
  1. Available Android targets:  
  2. [1] Android 1.5  
  3.      API level: 3  
  4.      Skins: HVGA-P, QVGA-L, HVGA-L, HVGA (default), QVGA-P  
  5. Available Android Virtual Devices: 

Indicates no AVD. If no AVD exists, an error occurs 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.