Debugging configuration of Android ndk on Ubuntu
When debugging local C/C ++ on Android, you can directly use GDB to debug it in the command line, which is very troublesome. The Sequoyah plug-in is used to integrate the debugging function into eclipse and debug it in the graphic interface. The reference below has already been explained in detail, and it takes a long time to build some points by yourself.
Refer to the following articles
Http://blog.csdn.net/dfqin/article/details/6901506
Http://www.eclipse.org/sequoyah/documentation/native_debug.php
Http://www.cnblogs.com/shadox/archive/2011/12/02/2272564.html
I. Environment Configuration
The ndkhandler I installed is android-ndk-r7b-linux-x86.tar.bz2. In addition, CDT and Sequoyah need to be installed and directly installed in eclipse.
1. Install CDT
2. Install the Sequoyah plug-in
3. Set Environment Variables
Add the following statement to/etc/profile:
Android_sdk_tools = $ home/Android-SDK-Linux/platform-Tools
Ndk_home = $ home/android-ndk-r7b/
Export Path = $ path: $ ndk_home: $ android_sdk_tools
After saving and exiting, execute source/etc/profile to use the environment variable to take effect.
4. In eclipse, choose Window> preferences> android to set the ndk location for local development.
2. Establish a test project
1. Create an android Project Orange. Modify the Java code as follows:
Package COM. gavin. example; import android. app. activity; import android. app. alertdialog; import android. OS. bundle; public class orangeactivity extends activity {/** called when the activity is first created. * // @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); New alertdialog. builder (this ). setmessage (sayhello ()). show () ;}public native string sayhello (); // native function static {system. loadlibrary ("orange ");}}
The code references a native function to obtain a string.
2. Right-click the project name and choose Android tools> Add native support.
In this interface, the ndk location can also be set. My environment may be faulty and the ndk location cannot be compiled. Therefore, it must be set in the previous step.
A jni directory should be added to the project directory, which contains two files: Orange. cpp and Android. mk.
3. Add a function in orange. cpp.
#include <string.h>#include <jni.h>extern "C"{jstring Java_com_gavin_example_OrangeActivity_sayHello( JNIEnv* env,jobject thiz );}jstring Java_com_gavin_example_OrangeActivity_sayHello( JNIEnv* env, jobject thiz ){ return env->NewStringUTF("Hello, I'm an Orange!");}
4. the following error message may be prompted during current compilation.
Method 'NewStringUTF' could not be resolved com_permadi_testJNI_TestJNIActivity.c /TestJNIC/jni line 6 Semantic ErrorType 'JNIEnv' could not be resolved com_permadi_testJNI_TestJNIActivity.c /TestJNIC/jni line 4 Semantic ErrorType 'jobject' could not be resolved com_permadi_testJNI_TestJNIActivity.c /TestJNIC/jni line 4 Semantic ErrorType 'jstring' could not be resolved com_permadi_testJNI_TestJNIActivity.c /TestJNIC/jni
Solution: properties-> C/C ++ General/paths and symbols-> Except des
Gnu c add/home/Gavin/android-ndk-r7b/platforms/Android-14/arch-arm/usr/include
The same is true for gnu c ++.
Reference http://permadi.com/blog/2011/09/creating-your-first-android-jnindk-project-in-eclipse-with-sequoyah
Compile the orange project. Start the simulator and test it. "Hello, I'm an orange!" should be displayed successfully! "String
5. Set the debug flag for compilation
Modify the project configuration file androidmanifest. xml and set the debuggable flag to true, as shown below:
3. Debugger Configuration
1. Find the ndk-GDB script under the ndk directory and comment out the last sentence.
# $ Gdbclient-x $ gdbsetup-e $ app_process
Now, go to the project directory in the command line and run the ndk-GDB command. New files such as app_process and GDB. Setup will be generated in OBJ/local/armeabi.
gavin@gavin-desktop:~/workspace/Orange$ ndk-gdb gavin@gavin-desktop:~/workspace/Orange$ ls obj/local/armeabi/app_process gdb.setup libc.so libOrange.so libstdc++.a objs objs-debug
Change the gdb. setup file to gdb2.setup and delete the last sentence.
Target remote: 5039
Select project-> debug as-> debug deployments, and create a configuration on the Right of C/C ++ application.
2. Main Tab
In C/C ++ application, enter the app_process file generated by the ndk-GDB command,/home/Gavin/workspace/orange/obj/local/armeabi/app_process
Click "select other..." at the bottom, select "use configuration specific setting", and select "Standard Crete process launcher" in the following box"
3. Debugger Tab
Select "gdbserver" in Debugger"
Gdb debugger:/home/Gavin/android-ndk-r7b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/ARM-Linux-androideabi-GDB
GDB command file:/home/Gavin/workspace/orange/obj/local/armeabi/gdb2.setup
Check the "verbose Console mode" at the bottom to output the gdb Command Information in the console.
Switch to the connection subtab
Select "TCP" as the protocol type, and enter "5039" as the port number"
Iv. debugging
1. Add a breakpoint when calling the native method in Java, set a breakpoint in the C ++ function, and start Java project debugging. At this time, the program should be interrupted when calling the native method.
2. Now run the command line to enter the project directory and run ndk-GDB. At the beginning, I ignored this step, and the following error occurred, entangled for two hours.
Target selection failed. Remote communication error: Connection reset by peer. Remote communication error: Connection reset by peer. Remote communication error: Connection reset by peer.
3. Project properties-> debug as-> debug deployments, select orange default configuration in C/C ++ application, and click "debug"