"Go" Compile the Android system source code and kernel source code

Source: Internet
Author: User

Original URL: http://blog.csdn.net/jiangwei0910410003/article/details/37988637

For a long time did not write blog, the reason is not written, mainly work on the matter, found that the recent brain is not enough to write something today? I have compiled the Android system source code and the kernel source of the process to record, because this process is really beneficial, value is not the result, mainly the process, in this process, I feel the greatest harvest is learning patience and perseverance, Because in this process the problem is like raining every day in your face, although there are many articles on the Internet how to operate, but I say the truth, those can only provide reference, because your work environment after all, and he is not the same, so you follow his steps to operate when you will encounter a lot of problems, Of course, I write this article is not to say that my method is sure to, I can only say that I was successful, so I just want to record, later can be viewed, the main or to see their perseverance and solve the problem of the ability, good not to say, say business ~ ~

First let's look at compiling the Android system source code

First: We know that the Android system is based on Linux development, so we want to compile the Android system source code, we must have a Linux system, here I use the Ubuntu 64-bit system, this image file is:

Http://pan.baidu.com/s/1c0eUSYc

Install Ubuntu System Needless to say, this kind of problem online information is very much, because the length may be very long, so if really need, please leave a message ~ ~

question one: As for why I use the 64-bit system, because in the back I will encounter a problem, that is, I first installed a 32-bit system, the result of the compilation process encountered a problem is:

error:prebuilts/tools/gcc-sdk/. /.. /gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6/bin/x86_64-linux-ar only run on 64-bit Linux

Compilation does not pass, I find the answer on the Internet, the following article is to say how to solve the problem, mainly to modify some of the specified files

Http://blog.sina.com.cn/s/blog_76dbbd7e01018cm5.html

But it is tragic: I follow his method of operation, and did not succeed, then how to do? I finally chose to reinstall a 64-bit system, but this time there is no virtual machine, directly installed in the computer.

problem Two: the installation of the time I have uninstalled in the installation system several times, the main reason is the first compile no experience, the beginning of the allocation of 20G space, the results of the compilation of silly, completely enough, so I directly to the computer 200G space are allocated out

Then after the installation system, there is a problem, when I go to use the same way to download Android source code, the discovery is always not connected, feel Google out of China, the source is very difficult to go to, in the middle only about one months of time, you can not download, good fake, tried various methods, I also buy a VPN, the result or not, then how to do? Before there is source code, but in the virtual machine, this time need to copy the source code in the virtual machine, then how to copy files from the virtual machine? This is very simple, I use the VM, he can set up a shared folder (specific method can search for a bit), but there is a problem, then in the virtual machine download is Android4.4 source, about 18G, I tried to copy, the results found that the best copy of the computer crashed, Mainly because the small file too much, about 600,000, the computer configuration is not good, so tried a few times is the crash, the copy does not come out how to do? The problem is to be solved, suddenly think of compression in the copy:

http://blog.csdn.net/jiangwei0910410003/article/details/37997899

Through an article in the above, compressed copy, the results found very good, and compression is very fast, this copy is smooth

So far we have solved the system problem and the source code problem

Note: The source code here is not referring to the problem of downloading the source code, I will say at the end of the current how to get the corresponding Android source code, anyway, download from Google I do not believe it. So I provided a connection that I had downloaded and played into a compressed package,

Http://pan.baidu.com/s/1mgoNVGs


Only need to decompress, on the unzip the Linux file, you can view another blog:

http://blog.csdn.net/jiangwei0910410003/article/details/37997899

The above prelude is done, and the following is the compile operation

The first step: before this need to install some auxiliary tools, to prevent the installation of the prompt error, of course, we can not install now, wait until the installation will prompt the corresponding error, then I only need to target to install, but that in the process of compiling will be very uncomfortable, so I still do these work

First you need to install the JDK, please go to another blog:

http://blog.csdn.net/jiangwei0910410003/article/details/37996723

Once the JDK has been installed, you will need to install the build library below:

sudo apt-get install GnuPG Flex Bison gperf Libsdl1.2-dev Libesd0-dev
sudo apt-get install Libwxgtk2.6-dev squashfs-tools build-essential
sudo apt-get install Zlib1g-dev pngcrush schedtool ia32-libs Libncurses5-dev

Of course, these must be installed, but not necessarily in the compilation of the time there is no problem, so we are in the compilation of problems encountered when we go to solve

Today in Ubuntu11.04 (64) compiled Android2.3 source code, encountered a variety of problems. It's not the lack of it, it's the less. These problems and solutions are listed for your reference

General error:
1. Error:
/usr/include/gnu/stubs.h:7:27:error:gnu/stubs-32.h:no such file or directory
Make: * * [OUT/HOST/LINUX-X86/OBJ/EXECUTABLES/ACP_INTERMEDIATES/ACP.O] Error 1
Solution:
sudo apt-get install libc6-dev-i386

2. Error:
Make: * * * [OUT/HOST/LINUX-X86/OBJ/EXECUTABLES/ACP_INTERMEDIATES/ACP] Error 1
Solution:
sudo apt-get install G++-multilib

3. Error:
External/clearsilver/cgi/cgi.c:22:fatal error:zlib.h:no such file or directory
Compilation terminated.
Make: * * * [OUT/HOST/LINUX-X86/OBJ/SHARED_LIBRARIES/LIBNEO_CGI_INTERMEDIATES/CGI.O] Error 1
Solution:
sudo apt-get install Zlib1g-dev

4. Error:
/usr/bin/ld:cannot Find-lz
Collect2:ld returned 1 exit status
Make: * * * [OUT/HOST/LINUX-X86/OBJ/EXECUTABLES/AAPT_INTERMEDIATES/AAPT] Error 1
Solution:
sudo apt-get install Lib32z1-dev

5. Error:
Bison-d-O out/host/linux-x86/obj/executables/aidl_intermediates/aidl_language_y.cpp frameworks/base/tools/aidl/ Aidl_language_y.y
/bin/bash:bison:command not found
Make: * * * [out/host/linux-x86/obj/executables/aidl_intermediates/aidl_language_y.cpp] Error 127
Solution:
sudo apt-get install Bison

6. Error:
Lex:aidl <= FRAMEWORKS/BASE/TOOLS/AIDL/AIDL_LANGUAGE_L.L
/bin/bash:flex:command not found
Make: * * * [out/host/linux-x86/obj/executables/aidl_intermediates/aidl_language_l.cpp] Error 127
Solution:
sudo apt-get install Flex

7. Error:
/usr/bin/ld:cannot find-lncurses
Collect2:ld returned 1 exit status
Make: * * * [OUT/HOST/LINUX-X86/OBJ/EXECUTABLES/ADB_INTERMEDIATES/ADB] Error 1
Solution:
sudo apt-get install Lib32ncurses5-dev

8. Error:
Prebuilt/linux-x86/sdl/include/sdl/sdl_syswm.h:55:fatal error:x11/xlib.h:no such file or directory
Compilation terminated.
Make: * * * [OUT/HOST/LINUX-X86/OBJ/EXECUTABLES/EMULATOR_INTERMEDIATES/ANDROID/MAIN-COMMON.O] Error 1
Solution:
sudo apt-get install Libx11-dev

9. Error:
Sh:gperf:not found
Calling Gperf failed:32512 at./makeprop.pl Line 96.
Make: * * * [out/target/product/generic/obj/static_libraries/libwebcore_intermediates/webcore/css/ CSSPROPERTYNAMES.H] Error 25
Make: * * * Deleting file out/target/product/generic/obj/static_libraries/libwebcore_intermediates/webcore/css/ CSSPropertyNames.h '
Solution:
sudo apt-get install Gperf
from:http://blog.csdn.net/offbye/article/details/6834285

The above error summary reference:
Http://www.360doc.com/content/12/0602/16/6828497_215429231.shtml

Fatal error: Bits/predefs.h: No file or directory compilation interrupt

Workaround:
sudo apt-get install Gcc-multilib

Reference:
Http://blog.sina.com.cn/s/blog_6340cd9c0101e42h.html

There is one more reason:

Ubuntu 11.10 Above the GCC version is 4.6.1, version is too high, compile Android error, to change the GCC version to 4.4.3

sudo apt-get install gcc-4.4
sudo apt-get install g++-4.4

Reference: http://blog.163.com/[email protected]/blog/static/4908666820121993234837/

Summary error:

1. Error

Host Executable:aapt (OUT/HOST/LINUX-X86/OBJ/EXECUTABLES/AAPT_INTERMEDIATES/AAPT)
/usr/bin/ld:skipping incompatible/usr/lib/gcc/x86_64-linux-gnu/4.4.5/. /.. /.. /libz.so when searching For-lz
/usr/bin/ld:skipping incompatible/usr/lib/gcc/x86_64-linux-gnu/4.4.5/. /.. /.. /LIBZ.A when searching For-lz
/usr/bin/ld:skipping incompatible//usr/lib/libz.so when searching For-lz
/usr/bin/ld:skipping incompatible//USR/LIB/LIBZ.A when searching For-lz
/usr/bin/ld:cannot Find-lz
Collect2:ld returned 1 exit status
Make: * * * [OUT/HOST/LINUX-X86/OBJ/EXECUTABLES/AAPT_INTERMEDIATES/AAPT] Error 1

Workaround:

Missing Lib32z1-dev, installation: Apt-get install Lib32z1-dev

2. Error
Compile-time/usr/include/gnu/stubs.h:7: fatal error:gnu/stubs-32.h:no Such file or directory error message
/usr/include/gnu/stubs.h:7: Fatal error:gnu/stubs-32.h:no such file or directory
Compilation terminated.
Make: * * * [OUT/HOST/LINUX-X86/OBJ/EXECUTABLES/ACP_INTERMEDIATES/ACP.O] Error 1
Workaround:

Missing LIBC Development Package, Installation: Apt-get install libc6-dev-i386

3. Error
Android compilation encountered error/usr/bin/ld:cannot find-lstdc++ resolution
Workaround:

Missing G++-multilib Library, installation: Apt-get install G++-multilib

Reference: http://www.mobiletrain.org/lecture/doc/android/2011-04/389.html

One of the last errors found:

Libwebcore.so error when make Android

Workaround: Increase file swap

Reference:
http://blog.csdn.net/zhoukejun/article/details/4211108

http://blog.163.com/tod_zhang/blog/static/1025522142013225112338311/

All right, all of this work is done, the mistakes are solved, the compilation is done, I compile at night, the second day is good, when I see the results, I am really happy:

Target system FS Image:out/target/product/generic/obj/packaging/systemimage_intermediates/system.img Install system FS Image:out/target/product/generic/system.img Target Ram disk:out/target/product/generic/ramdisk.img Target UserData FS image:out/target/product/generic/userdata.imgInstalled file List:out/target/product/generic/installed-files.txt

Then let's run the results of the compilation below:

1. Set environment variables:
[email protected]:~/android$ export path= $PATH: ~/android/out/host/linux-x86/bin  
[email protected]:~/android$ Export Android_product_out=~/android/out/target/product/generic

where ~/android/out/host/linux-x86/bin has the emulator command we want to execute, and ~/android/out/target/product/ Generic is an android image storage directory, which is used when executing the emulator command.
2. Run the emulator. The
[email protected]:~/android$ emulator
Emulator requires four files to run, namely Linux Kernel Mirror Zimage and Android image files System.img, userdata.img, and ramdisk.img. When you execute the emulator command, if you do not have any parameters, the Linux kernel image defaults to the Kernel-qemu file in the ~/android/prebuilt/android-arm/kernel directory. The Android image file uses the system.img, userdata.img, and ramdisk.img in the Android_product_out directory by default, which is the image problem we just compiled.
Of course, we can also run the emulator with the specified image file, that is, when you run emulator:
[email protected]:~/android$ emulator-kernel. Prebuilt/android-arm/kernel/kernel-qemu-sysdir./out/target/product/generic-system System.img-data userdata.img- RAMDisk ramdisk.img

But here's another mistake:

Emulator:ERROR:You did not specify a virtual device name, and the system
Directory could not being found.
If you are a Android SDK user, please use ' @<name> ' or '-avd <name> '
To start a given virtual device (SEE-HELP-AVD for details).
Otherwise, follow the instructions in-help-disk-images to start the emulator

Workaround:

Go to the Android source directory to execute:

SOURCE build/envsetup.sh

Lunch Sdk-eng

And then do it again:

Emulator

can start the simulator

Reference: http://blog.csdn.net/yf210yf/article/details/9206269

Run again, okay, here's the result:

After compiling the Android source code, write still have to see how to compile the Android kernel source code, why to compile the Android kernel source? This is for the follow-up work to prepare, the latter will say, in fact, we compiled above the android source code of his core Google has been compiled, stored in: Source directory /prebuilt/android-arm/kernel/kernel-qemu ;

Below we will see how to compile the kernel source code, the same, want to compile the kernel source, we need the kernel source code, is a pain, the internet has a lot of resources are said to use the goldfish version, and then go:git clone/http Android.googlesource.com/kernel/goldfish.git
Anyway, I was the download failed, the reason and download source is the same, Google Server connection failed, how to do?
At that time I was no way, go to all kinds of search, results some people say goldfish is not connected, someone will be the kernel source on GitHub, the address is as follows:
Https://github.com/android/kernel_common

If the download fails, I have downloaded it, you can go to the following link to download:

Http://pan.baidu.com/s/1pQzPs

I went to download it, about hundreds of m, after downloading it, compile it, before compiling we need to modify something:

Modifying the compilation environment in a makefile file in a folder

Will

ARCH = (subarch)
Cross_compile? =

Modified into
ARCH? = Arm
Cross_compile? = arm-eabi-

With the ARM architecture, cross-compiling uses the Arm-eabi-xxx tool, which is just a prefix

Let's compile it, go to the folder to compile the results found that the specified ARM-EABI-GCC tool is not found (this error occurs when I compile the Android4.4 version, because this version of the source code can not find the specified prebuilt/linux-x86/ Toolchain/arm-eabi-4.4.3/bin directory, but finally compiled the Android2.3.7 version of the words, so for the 4.4 version of the No, we will have to go online search this tool,:
http://download.csdn.net/download/storeage/4036993), after the download is generally stored in the/usr/lib directory, and then modify the environment variables, this can refer to the previous configuration of the JDK environment variable method

First need: Makegoldfish_defconfig

But cannot find the specified file, found this file only in goldfish version, and we download is Kernel_common, this time we can:

Make Menuconfig

Then choose the corresponding configuration, but the problem comes again, which options are required, which is not required, anyway, the final compilation always failed, hurt, so still have to find goldfish version of (I have introduced the Kernel_common version of the above, is to record the process of my operation, Although finally failed, but the luck is very good, and finally really I found, the specific address I remember not very clear, but I put on the net disk, there are corresponding instructions, goldfish:

Http://pan.baidu.com/s/1qW0TkkO

After downloading it, you can compile it,

Make Goldfish_defconfig

And then

Make

This compilation process is fast, less than one hours.

Objcopy Arch/arm/boot/zimage
Kernel:arch/arm/boot/zimage is ready

This compiles successfully, then I use this kernel image to start the simulator:


1. Before starting the emulator, set the emulator directory to the environment variable $path:
[Email protected]:~/android$ export path= $PATH: ~/android/out/host/linux-x86/bin
2. Set the ANDROID_PRODUCT_OUT environment variable:
[Email protected]:~/android$ Export Android_product_out=~/android/out/target/product/generic
3. In the background, specify the kernel file to start the emulator:
[Email protected]:~/android$ emulator-kernel./kernel/common/arch/arm/boot/zimage &

Unfortunately the simulator is bootable but always black screen , and the ADB shell is also not connected to the device, this can do, are almost successful, and then go online again to find the answer, Found: The reason is that my source code is 4.4 version, 2.3 version after the architecture is ARMV7, so not:

Make Goldfish_defconfig

But

Make Goldfish_armv7_defconfig

Once again, the success is to use the image file to start the simulator, grass, dumbfounded, the result or failure too painful, and then a variety of search, the reason above the answer, but I have modified, or not (this problem tangled two weeks, I almost gave up), and finally think is not the source of the problem, can only think so, So go to the night to find the source of 2.3.7, don't say a day, is really not negative people, but really I found, and found a lot of versions, are compressed package form, here I really want to thank this person, understand the resources to share,

Android2.3.7 Source:

Http://pan.baidu.com/s/1eQ9YT6i

Then I was very excited to recompile the Android2.3.7 version of the source (in fact, I was a bit worried, because I am now the system is 64 bits, do not know how many bits of this source, but the final compilation is successful, this version is 64 bits, there is no need to re-exchange system), Because of the previous compilation process, a lot of problems are solved in advance, the compilation process is very smooth, but also in the evening compiled results are also successful, this time we are in the way above to compile the kernel, and then start the simulator, wipe, the results can be:

Success, this time is really successful, good moved, good excited, two setbacks two times excitement ~ ~

Summary: In fact, we can review the above process, the individual feel that there is no technology, I encountered the biggest problem is the resources can not get the problem, so I will use the resources are given the download link, and feel that the problem can not be timid, to face ~

PS: The above process is my feeling and operation after success, if the parents do not succeed in my way, please leave a message ~ ~ I will help to see ~ ~

Note: This article is actually nothing, but there are a lot of related resources download connection, this is really valuable ~ ~

"Go" compile the Android system source code and kernel source code

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.