Previously wrote an article about Android native development, debugging (http://www.cnblogs.com/yaozhongxiao/archive/2012/03/13/2393959.html)
Recently participated in the project is also related to this part, found that with the continuous development, debugging has become more and more simple, it should be proven that science and technology is the first productivity ah, you read and found that debugging native gradually become not a problem
ndk:android-ndk-r9n
Eclipse:android Download the integration pack, which already contains the complete environment required for ADT, etc.
Set the path to the NDK in Eclipse, then start creating the project, and debug
First, create Android project
Second, add native support
Third, check the structure of the project directory is normal
At a glance, the simple operation of the entire project is established.
Four, switch to C + + view, easy to write-C + + code
Five, such a complete project is created, the next thing we want to do is to click on the button to display the string returned from JNI.
1. Modify the Activity_main.xml layout file
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"Xmlns:tools="Http://schemas.android.com/tools"Android:layout_width="match_parent"Android:layout_height="match_parent"><Textviewandroid:id="@+id/textview1"Android:layout_width="wrap_content"Android:layout_height="wrap_content"Android:layout_centerhorizontal="true"Android:text="@string/hello_world"android:textsize="@dimen/font_size"/><Buttonandroid:layout_width="wrap_content"Android:layout_height="wrap_content"android:layout_centerinparent="true"Android:onclick="Call_jni"Android:text="@string/call_jni"/></relativelayout>
2. Modify Mainactivity.java
Public classMainactivity extends Activity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_ Main);} Public voidCall_jni (View v) {((TextView) Findviewbyid (R.id.textview1)). SetText (Jni_call ());}Privatenative String Jni_call ();Static{system.loadlibrary ("debugndktest");}}
3. Get the JNI header file for Jni_call
$ cd $DebugNdkTest/-classpath. /bin/classes com.linguofeng.debugndktest.MainActivity
4. Modify DebugNdkTest.cpp
" Com_linguofeng_debugndktest_mainactivity.h " * env, jobject) {return env->newstringutf ("Hello from JNI" );}
Vi.. Operation
Seven, the next is the debug, debug before you need to modify the project properties
Eightmake a breakpoint on line 6th of the DebugNdkTest.cpp file
When you click the Access JNI button will stop at the breakpoint, now you can debug like Java debugging, very convenient.