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.
分享到:
相关推荐
`serial_jni_largestgle_Androidjni_Android串口操作JNI代码_android_`这个项目就是关于如何使用JNI来实现Android设备的串口读写的示例。 首先,我们需要了解JNI的概念。JNI是Java平台提供的一种接口,允许Java代码...
1. **JNI基础**:JNI是Android平台上的一个接口,它为Java应用程序提供了一个桥梁,使得开发者可以使用C或C++编写部分代码,以提升性能或者利用现有的C/C++库。JNI包括一系列的函数调用,如`JNIEnv`指针,用于在Java...
Android JNI(Java Native Interface)是Java平台的一部分,它允许Java代码和其他语言写的代码进行交互。JNI在Android系统中扮演...随着对JNI的深入理解和实践,开发者可以构建出更高效、功能更丰富的Android应用程序。
JNI是Android提供的一种接口,使得Java应用程序可以调用C/C++编写的原生代码。这在需要高性能计算、访问硬件特性或利用已有的C库时特别有用。JNI的核心在于`JNIEnv`指针,它是Java虚拟机与本地代码之间的桥梁,提供...
Android JNI(Java Native Interface)是一种在 Android 中使用 native 代码的接口,它允许开发者在 Android 应用程序中使用 native 代码,以提高应用程序的性能和安全性。JNI 提供了多种实现方式,这些方式可以根据...
5. **日志记录**:当JNI抛出异常时,记录详细的日志信息有助于调试,可以使用`__android_log_print()`函数输出日志。 6. **捕获和处理本地异常**:虽然JNI不直接支持try-catch,但可以通过在本地代码中设置错误标志...
9. **总结**:这个教程资料“Android--JNI-Device.zip”对于希望深入了解Android硬件驱动开发的开发者来说非常有价值,它将帮助开发者学习如何利用JNI高效地与设备驱动进行交互,提高应用程序的性能和功能。
在Android应用程序开发中,有时需要访问底层硬件功能或者优化性能,这时就可能需要用到JNI(Java Native Interface)技术来调用C/C++代码。JNI允许Java应用程序与本地代码进行交互,包括操作系统内核、驱动程序等。...
- **应用程序APP**:这部分包含Android应用的Java代码,它负责调用JNI函数并传递参数,如控制LED的命令。 - **JNI代码**:这是C/C++编写的本地代码,实现了与硬件交互的具体逻辑。JNI函数会被Java代码通过`System....
开发者可以使用JNI调用本地库,提高应用程序的性能,或者利用Android系统不直接支持的库。JNI接口定义了如何在Java代码中声明本地方法,以及如何在本地代码中实现这些方法。 2. **Android I2C通信**:在Android平台...
### Android Studio JNI调试详解 #### 一、JNI环境搭建概览 在开发Android应用时,有时需要使用到原生C/C++代码以提高程序性能或利用已有库。JNI(Java Native Interface)则作为连接Java与C/C++的桥梁,允许我们...
Android NDK(Native Development Kit)是一套工具,提供了编译、构建、调试本地代码的功能,使得开发者可以在Android应用中使用JNI技术。 八、Android Studio与JNI集成 现代Android开发中,大部分开发者使用...
在Android设备上,串口通常用于调试、物联网(IoT)设备连接或与硬件模块通信等场景。多串口同时收发意味着应用程序可以同时管理并操作多个串口,实现并发的数据传输,这对于需要连接多个外部设备的应用来说至关重要。...
7. **测试与调试**:使用Android Studio的NDK支持进行编译和运行,利用adb调试工具查看日志,定位问题。 在实际项目中,`serialtest`可能是用于测试串口通信功能的样例程序,包含了JNI接口的实现以及相关的配置文件...
在Android中,`Log`类提供了方便的方法来记录应用程序的调试信息。可以通过`Log.d()`, `Log.i()`, `Log.w()`, `Log.e()`等方法输出不同级别的日志,然后通过`adb logcat`命令在开发环境中查看这些日志。 总结一下,...
首先,我们需要理解Android的NDK(Native Development Kit),它是Android提供的一套工具,用于在C/C++环境中编写部分应用程序,然后通过JNI与Java层进行交互。要实现JNI调用Python解释器,我们需要以下步骤: 1. *...
"Android JNI 调试打印 char 数组的实例详解" Android JNI 调试打印 char 数组的实例详解是 Android 开发中的一种常见需求,特别是在 debug 和测试阶段。在 Android 中,使用 JNI 调用 native 方法时,需要将 char...
这是一个重大的进步,因为它极大地改善了Android开发者对本地代码的调试能力,特别是对于那些需要使用C/C++编写高性能或系统级功能的应用程序。 JNI是Java平台中用于在Java代码和本地(非Java)代码之间建立桥梁的...
### Eclipse里Android JNI的开发方法 #### NDK开发环境安装 **Native Development Kit (NDK)** 是由Google提供的工具集,旨在支持开发者使用C或C++编写原生代码,并能够将其与Java应用相结合,最终打包成APK。通过...
解压后,使用Android Studio或NDK工具链进行编译和调试。 通过这样的方式,你可以将C++实现的AES256加密集成到Android应用中,充分利用C++的性能优势,同时保持Java的便捷性。记得在实际项目中,还需要考虑错误处理...