7.1驱动程序调试――printk(串口打印)
a)添加代码
在代码中需要打印的地方插入printk语句
b)打开超级终端或者minicom
打开windows下的超级终端或者linux下的minicom。设置好端口等。
c)连接打印
连接上usb,当运行到打印语句后,打印信息即打印到超级终端或者minicom下
7.2 应用程序调试――logcat (adb调试)
a)添加代码
在代码中需要打印的地方插入logcat语句
b)打开adb,连接设备
连接上设备
先断开adb服务sudo ./adb kill-server
再打开adb服务sudo ./adb start-server
查询设备adbdevices如果可以查询到即表示已经连接上
c)打印
输入adblogcat显示打印信息
PS:
常用adb命令
adb help
sudo ./adbkill-server
sudo ./adbstart-server
adb devices
adb logcat e.g:adb logcat | grep MyApp (过滤adb logcat输出)
adb install
adb uninstall
adb push <source><destination></destination></source>
adb pull <source><destination></destination></source>
ps:不要在adb shell 中执行上面命令.
adb shell
adb shell am
eg:
打开一个网站
adbshell am start -n com.mx.browser/.MxBrowserActivity -dhttp://dev.eping.net
发送短信
adbshell am start -a android.intent.action.SENDTO -d sms:10086 --essms_body hello
adb 打电话
adbshell service call phone 2 s16 “10086”
android consolecommand:
telnet localhost 5554连接模拟器后;输入hep,可以查看到androidconsole command
eg: sms send 10086 haha
7.3 源码模拟器
http://source.android.com/source/downloading.html
a)查询
查看本机cpu位数
vim/proc/cpuinfo; 其中clflushsize为cpu位数
查看ubuntu位数
getconfLONG_BIT
或uname-ar
查看ubuntu版本
cat/etc/issue
b)编译
source ./build/envsetup.sh
lunch full-eng
make –j4
PS:该编译针对64位CPU,64位系统。对于其他配置需要更改代码。
c)运行
cdGoogle-source/out/target/product/generic/
emulator (-avdAVD2.3.3)-systemsystem.img -data userdata.img -ramdisk ramdisk.img
7.4 Eclipse调试
通过eclipse开发应用程序,可以打开断点,单步运行,打印信息,ddms等方式调试。
Eclipse也可以连接真机调试。
方法为:
选中项目,点Properties,选中target,点击edit,选择manual,运行,运行后选中硬件设备即可。
PS:windows用户可能需要安装在eclipse中安装googleusb driver package
并且安装USB驱动程序android-sdk\extras\google\usb_driver
7.5 Eclipse平台源码调试
参见网页source.android.com/source/using-eclipse.html
a)打开源码模拟器
cdGoogle-source/out/target/product/generic/
emulator(-avd AVD2.3.3) -system system.img -data userdata.img -ramdiskramdisk.img
b)更改eclipse.ini
-Xms512m
-Xmx1024m
-XX:MaxPermSize=512m
c)导入工程
cd进入工程根目录
cp./development/ide/eclipse/.classpath ./
将工程导入到eclipse中,导入时需选择JAVA工程,
并可更改.classpath内容。
Ps:导入后的错误不用更改。
d)设置端口
选中Run->Debugconfiguration->Remote java application,然后,”host:”设为localhost,
“Port:”设为8700,”connectiontype”为stand(socketattach),然后”apply”.
e)调试程序
e1)打开eclipse中的ddms,在ddms中选择一个进程;
e2)然后切换到java视图,选中项目单击右键,DebugAs->Debugconfigurations,单击Debug按钮。再切换到ddms视图,查看之前选中的进程前面是否出现绿色蜘蛛图标,这表示调试设备已经连接上了;
PS:要再DDMS中选中一个一个进程,才能在eclipse中debug
e3)在eclipse调试时,可以设置断点,单步调试等。
7.6 Eclipse平台源码模块调试
a)创建android工程
File-> new -> android project -> create project from existingsource -> ……
Ps:注意工程名要与根文件夹名相同;
且需更改包名,不要用系统包名
(可以通过更改androidmanifest.xml包名和search->file等方法替换,最好在包名上通过F2更改包名)
b)导入库
b1)新建
右击工程,选择build path -> configure build path -> libraries ->addlibrary->
Userlibrary-> ..- >new …
b2)添加
addjars
out/target/common/obj/JAVA_LIBRARIES/core_intermediates/
framework_intermediates/classes.jar
android-common_intermediates/classes.jar
core_intermediates/classes.jar
b3)调整顺序
将自己创建的库作为第一个库文件
b4)刷新
右击工程,点击refresh
c)调试
在DDMS中选中进程,进行调试(步骤同7.5内容)