Android2.2 source code compilation-ubuntu10.04 (x86) + android2.2 + jdk1.6

Source: Internet
Author: User
Tags uncompress

Android2.2 source code compilation

Environment: -- ubuntu10.04 (x86) + android2.2 + jdk1.6

Note: The official statement is that JDK 1.5 must be used in a 32-bit system. This is because Android API docs is compiled.
Requires 1.5. To use JDK, you must use a 64-bit system-why is it 64. If you want to succeed at a time, you 'd better use jdk1.5 as officially said (of course you use 64-bit
Linux is more convenient). In this case, there is basically no big problem.

1) install necessary software environments

View
Source

Print
?

1 $
sudo
apt-get
install
git-core gnupg sun-java5-jdk flex bison gperf
libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl
libncurses5-dev zlib1g-dev

This is officially recommended. If some commands cannot be found during compilation, Apt-Get it. Possible packages are:

View
Source

Print
?

1 1 $
sudo
apt-get
install
make2 $
sudo
apt-get
install
gcc3 $
sudo
apt-get
install
g++4 $
sudo
apt-get
install
libc6-dev5 $
sudo
apt-get
install
patch6 $
sudo
apt-get
install
texinfo7
$

sudo
apt-get
install
zlib1g-dev8 $
sudo
apt-get
install
valgrind9 $
sudo
apt-get
install
Python2.5 (or
Higher Version)

Note:

1. Official documents said that if you use sun-java6-jdk problems, you have to use sun-java5-JDK.

2. tests showed that if only make (make does not include make SDK), it is no problem to use sun-java6-jdk. Make
SDK, there will be problems, strictly speaking, in make
If a problem occurs with the doc, The javadoc version required is 1.5. Therefore, we 'd better install the sun-java6-jdk after installing the sun-java5-jdk, or just install
Sun-java5-jdk. Here sun-java6-
Jdkand sun-java5-jdkare both installed, and only javadoc.1.gz and javadoc are modified. Because only these two are 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-java6-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

When you encounter a 32-bit jdk1.6 system check problem, you can solve it through the following methods:

Modify the following files:

1
External/clearsilver/cgi/Android. mk,

2

3
External/clearsilver/Java-JNI/Android. mk,

4

5
External/clearsilver/util/Android. mk,

6

7
External/clearsilver/CS
/Android. mk four files.

Changing ifneq in the following script to ifeq can avoid problems temporarily

1
# This forces a 64-bit build
For java6

2
Ifneq ($ (Filter
1.6%, $ (java_version )),)

3
Local_cflags + =-M64

4
Local_ldflags + =-M64

5
Endif

2) Set environment variable 1
$ Gvim ~ /. Bashrc

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

01
# Java program development/running environment variables

02
Java_home =/usr/lib/JVM/Java-6-sun

03
Jre_home =$ {java_home}/JRE

04
Export
Android_java_home = $ java_home

05
Export
Classpath =. :$ {java_home}/lib: $ jre_home/lib: $ classpath

06
Export
Java_path =$ {java_home}/bin: $ {jre_home}/bin

07
Export java_home;

08
Export jre_home;

09
Export classpath;

10
Home_bin = ~ /Bin/

11
Export
Path =$ {path }:$ {java_path }:$ {home_bin };

After saving, synchronously update:

1
Source ~ /. Bashrc

3) install repo (used 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) repo Initialization

Repo is an android package for git, which simplifies some git operations.

Create a project directory:

1
$ Mkdir android

2
$ CD android

Repo Initialization

1
$ Repo init-u
Git: // android.git.kernel.org/platform/manifest.git

In this process, enter the name and email address. After the initialization is successful, the following message is displayed:

Repo initialized in/android

In ~ /There will be a hidden directory of. Repo in Android.

5) synchronize source code 1
$ Repo sync

This step takes a long time

6) Compile the android source code and get ~ /Android/out directory

1
$ Cd ~ /Andoird

2
$ Make

This process took a long time. After watching a movie for more than an hour, I compiled it. I have configured it on my computer ~

7) run the compiled Android SDK on the simulator.

After compiling Android,

Emulator IN ~ /Android/out/host/linux-x86/bin,

Ramdisk. IMG, system. IMG, and userdata. IMG are ~ /Android/out/target/product
1 In/generic
$ Cd
~ /Android/out/host/linux-x86/bin

Add environment variable

1
$ Gvim ~ /. Bashrc

Add environment variables in. bashrc as follows:

1
# Java program development/running environment variables

2
Export
Android_product_out = ~ /Android/out/target/product/generic

3
Android_product_out_bin = ~ /Android/out/host/linux-x86/bin

4
Export
Path =$ {path }:$ {android_product_out_bin }:$ {android_product_out };

Finally, synchronize these changes:

1
$ Source ~ /. Bashrc

2
$ Cd
~ /Android/out/target/product/generic

3
$ Emulator-System
System. IMG-data userdata. IMG-ramdisk. img

After entering the android desktop, it means the operation is successful.

8) Compilation Module

An application in android can be compiled separately. After compilation, system. IMG must be regenerated.

Run 1 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: 1
$
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

Available

1
$ Make Snod

Regenerate system. IMG and then run the simulator.

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.

A)
(This step is not required. Check your configuration.) 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;

C)
Run make SDK.

Note that the javadoc version needed here is 1.5, so you need to install the sun-java5-jdk1 at the same time in step 1
$ Make SDK

Compilation is slow. The SDK generated after compilation is stored in the out/host/linux-x86/SDK/, this directory has Android-
Sdk_eng.xxx_linux-
X86.zip and android-sdk_eng.xxx_linux-x86 directory. Android-sdk_eng.xxx_linux-x86 is
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 remove the android-sdk_eng.xxx_linux-x86
Come

This SDK will be used for subsequent application development ~ /. Comment out the changes to bashrc and add the following line:

1
Export
Path =$ {path }:~ /Android/out/host/linux-x86/sdks/android-sdk_eng.xxx_linux-x86/tools

Replace xxx with a real path;

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 will not be used, because these tools and IMG do not
After SDK classification, tools and configurations cannot be found. In fact, make
Many tools and IMG generated by the 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 use the android tool to view: 1.
$ Android list

Create AVD: 1
$ 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.

Add the-AVD myavd or @ myavd option to emulator every time you run emulator: 1

$ 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 variable 1
$
Gvim ~ /. Bashrc

Add the following two rows:

1
Export
Path = $ path :~ /Android/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin

2
Export arch = arm

Synchronization changes after saving: 1
$ Source ~ /. Bashrc

C)
Obtain appropriate kernel source code 1
$
Cd ~ /Android

Obtain the kernel source code repository

1
$ Git clone
Git: // android.git.kernel.org/kernel/common.git Kernel

2
$ CD Kernel

3
$ 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: 1
$ 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.

1
$ Git checkout-B
Android-goldfish-2.6.29 origin/Android-goldfish-2.6.29

2
$ 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

1
Ldflags_build_id =
$ (Patsubst-wl $ (comma) %, % ,/

2
$ (Call LD-option,
-Wl $ (comma)-Build-ID ,))

Comment out this line and add an empty ldflags_build_id definition, as shown below: 1

Ldflags_build_id =

E)
Compile the kernel Image

1
$ Cd ~ /Android/kernel

2
$ Make goldfish_defconfig

3
$ Make

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

========================================================== ============================

Finally, various errors may occur during the compilation process. You can search for them by Google. Common Errors can be found. I wish you success. OK to close the job ~

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.