Android源码开发和调试环境搭建
•开发机器配置
•Android源码下载、编译和运行
•Linux内核源码下载、编译和运行
•Java代码开发和调试
•C/C++代码开发和调试
开发机器配置
•硬件
–CPU I5及以上
–内存16GB及以上
–硬盘40GB及以上
•软件
–Ubuntu 10.04 64bit
–Java SDK 1.6
–其它Package
–http://source.android.com/source/initializing.html
Android源码下载
•$ mkdir ~/bin
$ PATH=~/bin:$PATH
$ PATH=~/bin:$PATH
•$ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
$ chmod a+x~/bin/repo
$ chmod a+x~/bin/repo
•$ mkdir WORKING_DIRECTORY
$ cd WORKING_DIRECTORY
$ cd WORKING_DIRECTORY
•$ repo init -u https://android.googlesource.com/platform/manifest -b android-4.2_r1
•$ repo sync
•http://source.android.com/source/downloading.html
Android源码编译和运行
•$ . build/envsetup.sh
•$ lunch full-eng
•$ make –j8
•$ emulator &
•http://source.android.com/source/building-running.html
Linux内核源码下载、编译和运行
$ git clone https://android.googlesource.com/kernel/goldfish.git
•$ cd goldfish
•$ git branch –a
–remotes/origin/android-goldfish-3.4
•$ git checkout remotes/origin/android-goldfish-3.4
•$ export PATH=$(AOSP)/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin:$PATH
•$ export ARCH=arm
•$ export SUBARCH=arm
•$ export CROSS_COMPILE=arm-eabi-
•$ make goldfish_armv7_defconfig
•$ make
•$ emulator –kernel kernel/goldfish/arch/arm/boot/zImage &
•http://source.android.com/source/building-kernels.html
Java代码开发和调试
可以直接下载adt ,adt/eclipse目录下直接执行./eclipse
•安装Eclipse
–$ sudo apt-get install eclipse
•拷贝.classpath文件,在安卓源码目录操作
–$ cd /path/to/android/root
–$ cp development/ide/eclipse/.classpath .
–$ chmod u+w .classpath
•修改Eclipse内存配置
–打开/usr/lib/eclipse/eclipse.ini
–将-Xms和-Xmx均设置为2048m
•导入Android源码到Eclipse
–File > New > Java Project
–Pick a project name, “android” or anything you like.
–Select “Create project from existing source”, enter the path to your Android root directory, and click Finish.
(Location目录选择安卓源码目录)
•新增App工程到Android源码工程
–Project > Properties
–Select “Java Build Path” from the left-hand menu.
–Choose the “Source” tab.
–Click “Add Folder…”
–Add your app’s src directory.
–Click OK.
•使用Eclipse调试Java源码
–启动emulator
•$cd/path/to/android/root
•$ . build/envsetup.sh 或者$ source build/envsetu.sh
•$ lunch
选择要调试的工程,敲数字,打回车
•$ emulator &
–打开ddms
•$ddms
•Select a process
–打开eclipse
•Run > Debug Configuration…
•Right-click “Remote Java Application”, select “New”.
•Pick a name, i.e. “android-debug” or anything you like.
•Set the “Project” to your project name.
•Keep the Host set to “localhost”, but change Port to 8700.
•Click the “Debug” button and you should be all set.
•http://source.android.com/source/using-eclipse.html
C/C++代码开发和调试
•安装Vim
–sudoapt-get install vim
•启动Emulator
–$ cd /path/to/android/root
–$ . build/envsetup.sh
–$ lunch 1
–$ emulator &
–$ adb shell
•在adbshell中启动gdbserver
–root@android:/ gdbserver :5039 –attach
•在另外一个终端启动gdbclient
–$ cd /path/to/android/root
–$ . build/envsetup.sh
–$ lunch 1
–$ adb forward tcp:5039 tcp:5039
–$gdbclient
•https://github.com/keesj/gomo/wiki/AndroidGdbDebugging