Android SDK source code compilation

Source: Internet
Author: User
Tags uncompress

1. Environment


Ubuntu 10.04 32-bit

Sudo apt-Get install Git-core

Sudo apt-Get install curl

Sudo apt-Get installZlib-Dev becomes sudo apt-Get install Zlib1g -Dev


Sudo apt-Get install bison

Sudo apt-Get install flex

Sudo apt-Get install libncurses-Dev (libncurses5-dev)

Sudo apt-Get install g ++

Sudo apt-Get install libx11-dev

Sudo apt-Get install gperf

Install Java 6



Java version: Java 6 can compile code but cannot generate documents. It is best to prepare two sets of Java environments.


Ubuntu 10.04 64-bit

sudo apt-get install libc6-dev-i386
sudo apt-get install lib32ncurses5-dev
sudo apt-get install libx11-dev
sudo apt-get install g++-multilib
sudo apt-get install lib32z1-dev
64-bit Java6

2. Download the android SDK


Curl http://android.git.kernel.org/repo> ~ /Bin/Repo

Chmod A + x ~ /Bin/Repo

If you want to take down all the sourcecodes in the latest version of the current Android main line, we need repo help.
First create a directory, such ~ /Android. Use the repo init command after entering the file.
Repo init-u git: // android.git.kernel.org/platform/manifest.git


Obtain the eclair code:

Repo init-u http://android.git.kernel.org/platform/manifest.git-B eclair


From Android 2.2, SDK compilation requires a 64-bit system and 32-bit, so you have to compile eclair first.


Repo init-u http://android.git.kernel.org/platform/manifest.git-B eclair

Repo sync



3. Compile


Make

CD eclair

../Build/envsetup. Sh

Make SDK

Run compiled android on the simulator
After compiling Android, emulator ~ /Android/out/host/linux-x86/bin, ramdisk. IMG, system. IMG and userdata. IMG are ~ /Android/out/target/product/generic
$ Cd ~ /Android/out/host/linux-x86/bin
Add environment variable
$ Emacs ~ /. Bashrc
Add environment variables in. bashrc as follows:
# Java program development/running environment variables
Export android_product_out = ~ /Android/out/target/product/generic
Android_product_out_bin = ~ /Android/out/host/linux-x86/bin
Export path =$ {path }:$ {android_product_out_bin }:: {android_product_out };

Finally, synchronize these changes:
$ Source ~ /. Bashrc
$ Cd ~ /Android/out/target/product/generic
$ Emulator-system. IMG-data userdata. IMG-ramdisk. img
After entering the android desktop, it means the operation is successful.


4. 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/


5.

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


9) Compile the SDK

Make product-SDK is required to compile the android SDK. Make SDK cannot be used directly,


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.

A) 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;

B) Compile ADT.
I did not perform this step because I do not use eclipse;

C) 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 and translation are slow. The compiled SDK is stored in out/host/linux-x86/SDK/, which has a android-sdk_eng.xxx_linux-x86.zip and a android-sdk_eng.xxx_linux-x86 directory. 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
This SDK will be used for subsequent application development ~ /. Comment out the changes to bashrc and add the following line:
Export path =$ {path }:~ /Android/out/host/linux-x86/sdks/android-sdk_eng.xxx_linux-x86/tools
Replace xxx with a real path;

# Make product-SDK

D) Selection of environment variables and Android tools
Currently, Android tools include:
A. the SDK we downloaded from the Internet, if you have downloaded it (there are many Android tools under 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 generally do not use the option tool and IMG, because it is generally old and the source code is not synchronized. Second, the C option tools and IMG are not used, because these tools and IMG are not classified by the SDK, and tools and configurations cannot be found. In fact, many tools and IMG generated by the make SDK are compiled when make is compiled out of the directory. The make SDK only implements copy.

E) install and configure ADT
Skipped;

F) 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
Create AVD:
$ Android create AVD-T 1-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.
The-AVD myavd or @ myavd option will be added for every running of emulator in the future:
$ Emulator-AVD myavd

10) Compile the Linux kernel Image
A) Prepare the cross-compilation tool chain
The android code tree contains a prebuilt project that contains the cross-compilation tools required for compiling the kernel.

B) Set Environment Variables
$ Emacs ~ /. Bashrc
Add the following two rows:
Export Path = $ path :~ /Android/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin
Export arch = arm
After saving, synchronize the changes:
$ Source ~ /. Bashrc

C) obtain the appropriate kernel source code
$ Cd ~ /Android
Obtain the kernel source code repository
$ Git clone git: // android.git.kernel.org/kernel/common.git Kernel
$ CD Kernel
$ Git Branch
Display
* Android-2.6.27:
It means that you are now in the branch Android-2.6.27, which is also the default main branch of kernel/common. Git.
Show all head branches:
$ Git branch-
Display
* Android-2.6.27:
Remotes/ORIGIN/head-> origin/Android-2.6.27
Remotes/ORIGIN/Android-2.6.25
Remotes/ORIGIN/Android-2.6.27
Remotes/ORIGIN/Android-2.6.29
Remotes/ORIGIN/Android-goldfsh-2.6.27
Remotes/ORIGIN/Android-goldfsh-2.6.29
We select the latest Android-goldfish-2.6.29, where goldfish is the CPU simulated by the android simulator.
$ Git checkout-B Android-goldfish-2.6.29 origin/Android-goldfish-2.6.29
$ Git Branch
Display
Android 2.6.27
* Android-goldfish-2.6.29
We have already worked on the Android-goldfish-2.6.29 branch.

D) set cross-compilation Parameters
Open the MAKEFILE file in the kernel directory and point cross_compile to the arm-Eabi compiler in the prebuilt you just downloaded.
Cross_compile? = Arm-Eabi-
Set
Ldflags_build_id = $ (patsubst-wl $ (comma) %, % ,/
$ (Call LD-option,-wl $ (comma)-Build-ID ,))
Comment out this line and add an empty ldflags_build_id definition, as shown below:
Ldflags_build_id =

E) Compile the kernel Image
$ Cd ~ /Android/kernel
$ Make goldfish_defconfig
$ Make

F) Test the generated kernel Image
$ Emulator-AVD myavd-kernel ~ /Android/kernel/ARCH/ARM/boot/zimage

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.