http://groups.google.com/group/android-ndk/browse_thread/thread/50362904ae0574cf/fe9703f5cc08714e

调试jni apk

http://vilimpoc.org/blog/2010/09/23/hello-gdbserver-a-debuggable-jni-example-for-android/

android 上ndk-build 编译可执行程序方法

http://vilimpoc.org/blog/2010/09/26/straightforward-android-native-executables/

1.

After doing much, much research and headaches, I believe I got

debugging to work FINALLY. I want to thank everyone here for there
responses. For those that want to try this, this is what I did:

note: The way I'm debugging here is on a simple mixed java/native c++
app (app that uses jni) using gdb. Most guides regarding this topic
of debugging native code involved a independent standalone c/c++
executable (runs from android shell), this is not the case here. This
is debugging on a java app that makes calls to code in c/c++.

setup: To do this you need an os that can get and build the android os
source, so linux or mac. For windows you can use a virtual machine of
linux (thats what I did vm linux mint)

the app: SimpleJNI (this sample app is part of android os source
located in development/sample/SimpleJNI), it demonstrates the concept

1. First get the Android OS source following the instructions here
http://source.android.com/downloadyou need to get it and make it.
2. Next follow the instructions herehttp://source.android.com/using-eclipse
to setup the eclipse and add the SimpleJNI app to the build path (most
important part to note here is adding the app to build path)
3. Now you need edit the app's Android.mk to add debugging symbols for
gdb. Go to SimpleJNI/jni folder in Android.mk and look for this line
"LOCAL_CFLAGS +=" change it to read "LOCAL_CFLAGS += -g"
4. cd /path/to/android/root and do "make SimpleJNI" to make the app.
5. Back in the Using Eclipse link follow these instructions from the
debugging with eclipse:

cd /path/to/android/root
. build/envsetup.sh
lunch 1 # to build the emulator
make # if you didn't already do this
emulator # you should see a GUI picture of a phone

Note: if your terminal can't seem to recognize the commands make sure
you are in the android root, and rerun ". build/ensetup.sh" and "lunch
1" commands

6. Next you need to install the app, from another terminal use this:
adb install -r ./out/target/product/generic/system/app/SimpleJNI.apk

7. You also need to push gdbserver in the emulator too, this will go
in /data/local directory
adb push ./out/target/product/generic/obj/EXECUTABLES/
gdbserver_intermediates/gdbserver /data/local

8. run the app SimpleJNI in the emulator, so it's running.

9. Follow the instructions herehttp://pdk.android.com/online-pdk/guide/debugging_gdb.html,
use the method of attaching to pid instead of executable

10. To see it work set a breakpoint i.e. b native.cpp:26, now since
there is no main() you can't just use <gdb> run, so what I found that
works is click "back" on the emulator and go back to android
homescreen. Then click open SimpleJNI again and gdb should break at
the breakpoint in this case line 26 in gdb.

11. In the emulator there should be no result displayed except for the
title SimpleJNI if you breaked at line 26

12. In the gdb window type "continue" or "c" and the app should resume
displaying some operation.

Thats it. I hope this was helpful because I felt there wasn't any
clear steps on how to debug w/ gdb/gdbserver on a java/jni app
scenario. I do think this method is very cumbersome and hopefully the
ndk later on will provide a better solution for debuging native code.





2. 一步一步

It is basically that

Then I am doing basically what you said and it is working. But I'll
write here the steps I am following:

cd AOS_ROOT
source build/envsetup.sh
lunch 1
emulator <--- it is important to run this emu instead of the one
included with the SDK

Recompile .so with NDK
cd to NDK_ROOT
make APP=<app_name>
Generate pkg (there are a lot of ways to do this, I am doing it with
eclipse (clean and build))
cp NDK_ROOT/out/apps/<app_name>/<app_name>.so AOS_ROOT/out/target/
product/generic/symbols/system/lib/<app_name>.so

cd to AOS_ROOT
adb install -r NDK_ROOT/apps/<app_name>/bin/<app_name>.apk
execute the installed application in the emulator
adb forward tcp:1234: tcp:1234
adb shell ps
adb shell gdbserver :1234 --attach pid <--- the pid displayed with ps

Open another terminal and cd to AOS_ROOT
prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-gdb out/
target/product/generic/symbols/system/bin/app_process
----INSIDE GDB ----
set solib-absolute-prefix out/target/product/generic/symbols
set solib-search-path out/target/product/generic/symbols/system/lib/
target remote :1234

Then a list of lines saying the symbols have been loaded appear and
you can insert breakpoints and debug as usual. I have changed the
behaviour of my app so that it stays doing nothing until I press down
in the keyboard, then the lib is loaded and executed, that way I have
time to attach the debugger.



更多相关文章

  1. android 监听方法
  2. Android中的“再按一次返回键退出程序”实现
  3. android sdk 自带的非空非空串判断方法
  4. Android用代码安装APK,不用选择“打包安装程序”
  5. android中的handler的使用方法
  6. Android下调整多媒体音量方法
  7. Android Studio出现Failed to open zip file问题的解决方法
  8. Android触控屏幕Gesture(GestureDetector和SimpleOnGestureListe
  9. Android 如何让程序定时进行消息通知到通知栏

随机推荐

  1. Android(安卓)控件之ProgressBar进度条
  2. Android(安卓)Material Design调色板
  3. Android(安卓)Studio最终篇 - 架构
  4. Android(安卓)通过代码实现控制数据网络
  5. Java(Android)线程池
  6. Android(安卓)开发调试工具的使用总结
  7. 使用android studio 来开发hello world a
  8. Android开发常用属性
  9. 关于android中几个Info系列类的总结
  10. Android之SQLite开发(2)—SQLiteOpenHelper