"Go" in Ubuntu compiled Android source code and run emulator

Source: Internet
Author: User
Tags valgrind

Original URL: http://www.mcuos.com/thread-4553-1-1.html

Building a compilation environment

1. On the VirtualBoxInstallationUbuntu

2. Installing the JDK
$ sudo apt-get install SUN-JAVA5-JDK or
$ sudo apt-get install SUN-JAVA6-JDK (Donut 1.6)
3. Install Flex,bison,gperf,libsdl-dev,libesd0-dev,libwxgtk2.6-dev (optional), Build-essential,zip,curl.
$ sudo apt-get install Flex Bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential Zip Curl Libncurses5-dev ZL Ib1g-dev
4. Install Valgrind (optional), thisTools to help you findErrors such as memory leaks, stack corruption, and array access out of bounds.
$ sudo apt-get install Valgrind
5.DownloadAndroidSource

Download Donut Branch from Android officialThe Android sourceCode
sudo apt-get install Git-core Curl
Curl Http://android.git.kernel.org/repo >~/bin/repo
chmod a+x ~/bin/repo

CD ~/bin/
$./repo init-u Git://android.git.kernel.org/platform/manifest.git-b android-1.6_r2
$./repo Sync

6. In ~/.BASHRC add environment variable.
$ vim ~/.BASHRC
In. BASHRCAdd the following 2 lines to the last side of the file to add the JDK installation path to the environment variable
Export Java_home=/usr/lib/jvm/java-6-sun
Export Android_java_home= $JAVA _home
Once completed, the $source ~/.BASHRC can take effect.

Running $ java-version will show the following prompt:
[Email protected] java]# java-version
Java Version "1.6.0_11"
Java (TM) SE Runtime Environment (build 1.6.0_11-b03)
Java HotSpot (TM) Client VMs (build 11.0-b16, mixed mode, sharing)
[Email protected] java]#
Indicates that Java has been successfully installed

Pass
$ update-alternatives--config Javadoc
$ sudo update-alternatives--config java
$ sudo update-alternatives--config javac
Then choose a number, then switch over.



compiling Android

$ cd Android//(Into AndroidDirectory
$ make//(compile Android)

Note:Compile-time to ensure thatThe system has more than 1.2GM of memory, and there is enough free space on the hard disk, otherwise the compilation fails to terminate.
The Android compilation environment provides the "showcommands" option to display the compile command line, such as:
$ make Showcommands


1.5_R2 version of the compiler error resolution:
The Android code contains a bug that hasn ' t been solved up to the date of this article.
So before your start compiling the code, you'll need a few modifications, or the build would fail (after consuming some of Y Our time and patience). The error is:
external/qemu/sockets.c:in function ' Sock_address_init_resolve ':
External/qemu/sockets.c:637:error: ' Eai_nodata ' Undeclared (first use
In this function)
External/qemu/sockets.c:637:error: (undeclared identifier is
Reported only once
External/qemu/sockets.c:637:error:for each function it appears in.)
Make: * * * [out/host/linux-x86/obj/executables/emulator_intermediates/
SOCKETS.O] Error 1
To fix this, before compiling the Android code, open ~/mydroid/external/qemu/sockets.c and add
#define __use_gnu
Just before the #Include <netdb.h>

the newly compiled system.img does not work properly with the SDcard workaround:
$ mount-t vfat/dev/block//vold/179:0/sdcard
You can also change the System/core/voldProgram


Run Emulator
Here we use the compiled emulator kernel image, which is Kernel-qemu, in the Android/prebuilt/android-arm/kernel directory, and then run the emulator.

1. In ~/.BASHRC add environment variable. (this option is optional)
$ vim ~/.BASHRC
On the last side of the. bashrc file, add the following 2 lines to the path of the Android tool
export Path=/archer/external/android/out/host/linux-x86/binpath
Export Android_product_out=/archer/external/android/out/target/product/generic

Export android_swt=/android/out/host/linux-x86/framework

2. Create an Android virtualEquipment
$ cd Android/out/host/linux-x86/bin (enter the directory where the emulator program is located)
$./android Create avd-t 2-n G1
Where-t specifies Targetid (the ID of the Android 1.5 SDK is 2,android 1.0 SDK ID is 1),-n Specifies the name of the Android virtual device created.

3. Running Emulator
$ cd Android/out/host/linux-x86/bin (enter the directory where the emulator program is located)
$./EMULATOR-AVD G1 or
$./EMULATOR-AVD G1-scale 0.8
Where-AVD specifies the Android device name,-scale specifies the zoom ratio.
Press Ctrl + F12 to make the simulator screen rotate 90 degrees, that is, horizontal screen, vertical screen switch.
4. Delete the created Android virtual device
$./android Delete Avd-n G1


compiling Linux kernel


Build Android directlySource code, and did not compile Linux kernel. If you run only the emulator, you do not have to compile Linux kernel.
Get from EmulatorConfiguration file for kernel compilation parameters:
Launch simulator
$ adb pull/proc/config.gz.
Uncompress config.gz $ gzip-d config.gz
Replace the config file with the. config file under the kernel folder.
Revise config and makefile configuration files as needed


compiling the module

One of the AndroidThe application can be compiled separately, and the system.img will need to be regenerated after compilation.
Running in the Android directory
$ . Build/envsetup.sh or
$ source build/envsetup.sh, and then there are a few more available 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 + + files.
-Jgrep:greps on all local Java files.
-Resgrep:greps on all local res/*.xml files.
-Godir:go to the directory containing a file.
-Printconfig: The configuration of the current build.
You can use--help to view usage.
For example, after modifying a module, you can use MMM < directory > to recompile all the modules in < directory >, using $ mm to compile all modules in the current directory.
After you have finished editing the Android system, you can regenerate the system.img using the Make Snod.

"Go" in Ubuntu compiled Android source code and run emulator

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.