Reproduced from: http://blog.sina.com.cn/s/blog_53e89d4f0100vom1.html
1 Create or import Java projects in the usual way.
2 Create a JNI directory under the project directory, all C + + code and MK files are placed in this directory.
3 Copy android.mk and application.mk from the sample directory to the JNI directory and modify the corresponding content.
4 If you have more than one C + + module, modify the Application.mk app_modules field, for example:
app_modules= FreeType MYAPP2
At the same time set up freetyp.mk,myapp2.mk, modify android.mk for:
Local_path: =$ (call My-dir)
include$ (Local_path)/freetype.mk
include$ (Local_path)/myapp2.mk
In other words: Android.mk can contain multiple modules of the Mk file.
5 If you want to use C + + library functions, add the APPLICATION.MK
app_stl:= stlport_shared
Add in Android.mk: (Note that the STLport header file directory is not added manually)
local_static_libraries+= libstlport_shared.so
In addition, all modules packaged into APK in Java code are to be manually load, otherwise they are abnormal: (unlike Windows is automatic load)
System.loadlibrary ("stlport_shared");
System.loadlibrary ("FreeType");
System.loadlibrary ("myapp2");
5 The Java project into C + + Hybrid project: File->new->other->c/c++->convertto a C + + project
6 on the project right key properties, modified as follows:
Cygwin/bin to join the system PATH environment variable. Ndk_root is the directory where the NDK resides and the system environment variables are added.
7 build project, successfully compile all modules.
8 Create a new Debug configuration:
C + + application is the obj\local\armeabi\app_process of the current engineering directory. Then click Selectother ...
Continue modifying properties:
Debugger:f:\android-ndk-r5b\toolchains\arm-eabi-4.4.0\prebuilt\windows\bin\arm-eabi-gdb.exe
File:f:\tj\at_utils\build\android\obj\local\armeabi\gdb.setup
9 into the NDK directory, the ndk-gdb file copied into the NDK-GDB2. Open the NDK-GDB2, shielding the last 1th and the last 5th sentence, the shielding method is the sentence front plus #:
#echo "Target Remote: $DEBUG _port" >> $GDBSETUP
If [-N "$OPTION _exec"]; Then
Cat$option_exec >> $GDBSETUP
Fi
# $GDBCLIENT-X ' Native_path $GDBSETUP '
10 in the Engineering Obj\local\armeabi directory to create a file called Dbg.bat, the contents of the file is:
Set android_ndk_root=/cygdrive/f/android-ndk-r5b
Bash%NDK_ROOT%/NDK-GDB2
(The figure is r5b version, do not need the first sentence, r5c version needs to define Android_ndk_root)
Now the setup work is complete and you can start debugging.
The debugging steps are:
1 Starting the Java program
2 after the start double-click Dbg.bat, this time will pop a small DOS window, do not close this window, inside is gdbserver. This window closes automatically when the user finishes debugging.
3 Click on the Debug button next to the Small triangle button, select Debug Configuration, find just the C + + aplication, click Debug. (See process 8)
This is the time to debug both Java and C + + code. However, debugging C + + code performance is very poor, speed is not generally slow.