Ndk-gdb to java/native Code co-commissioning (upgrade version)

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.