2010年8月19日星期四

How to build Android source code from source.android.com

Start from the clean Ubuntu 10.04 install, and target to build the Android Éclair.
Learn from : http://devtcg.blogspot.com/2009/03/building-running-and-debugging-android.html
and http://mmmyddd.freeshell.net/wiki/android/build.html.

1. Follow the http://source.android.com/source/download.html instruction,

a) Setup the development environment:

i. $ 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

ii. $ sudo apt-get install valgrind

2. install and use repo

a) $ curl http://android.git.kernel.org/repo > ~/bin/repo

b) $ chmod a+x ~/bin/repo

3. get source from source.android.com

a) $ mkdir ~/android/éclair; (this folder will be the root folder for build and debug, all command invoke will be from this folder).

b) $ cd ~/android/éclair

c) $ repo init -u git://android.git.kernel.org/platform/manifest.git -b éclair

Note: -b specified the branch, code name is the branch, like éclair, cupcake, donut and froyo.

d) $ repo sync

4. Build the eclair

a) Before build the android, some commands suggest to invoke:

i. $ source ./build/envsetup.sh

ii. $ lunch 1

b) Need export JAVA_HOME and add PATH

 $ export JAVA_HOME=/usr/lib/jvm/java-1.50-sun

 $ export ANDROID_JAVA_HOME=$JAVA_HOME

c) $ make

5. After build success, invoke the ./out/host/linux-x86/bin/emulator to start the android emulator.

6. Import the Android platform source code into eclipse. (we don’t need Android SDK and ADT tool, since we are going to debug the Android build-in application and all tools has been built in the folder ./out/host/linux-x86/bin. Follow the steps from http://source.android.com/source/using-eclipse.html.

Note: create a JAVA project. Not a Android project.

7. Launch ./out/hot/linux-x86/bin/ddms to start the debugging. Once ddms starts, attach the Android process on local machine port 8700 to debug.

8. Blocks the selected application from loading until a debugger attaches. This way you can set a breakpoint in onCreate(), which is important to debug the startup process of an Activity. When you change this option, any currently running instances of the selected application will be killed. In order to check this box, you must have selected a debug application as described in the previous option. You can do the same thing by adding waitForDebugger() to your code.

9 after add android.os.Debug.waitForDebugger(); in first line of onCreate of settings.jave, use following command to rebuild the module and image, of course shutdown the emulator first
$ mmm packages/apps/Settings // rebuild the settings apk
$ make snod // rebuild the system.img
then restart the emulator, select settings, now can attach and debug the application startup.





没有评论:

发表评论