One of the Android NDK debugging methods: ADB Logcat

Source: Internet
Author: User

View log information that is printed during program execution to assist in debugging the exclusion code errors.

First, using the NDK installation package under the SAMPLES/HELLO-JNI project to do experiments

1) Modify the Jni/hello-jni.c file

#include <android/log.h>"hellojnitag""thevalue is%d " );

2) Modify the Jni/android.mk file

Local_path: = $ (call My-dir) include $ (clear_vars) local_module    := hello-jnilocal_src_files:= hello-jni.clocal_ldlibs    :=   -lloginclude $ (build_shared_library)

3) Use Eclipse to open the current project, run the test, Debug as ...

4) Observe log information in Eclipse's logcat monitoring window

Ii. General steps for NDK development

1) launch Eclipse to create Android application project;

2) Create Activity application class (can imitate Hellojni in Hellojni.java);

3) Add native function declaration and invocation in activity application class;

 Public nativeString Stringfromjni (); /*This is another native method declaration, which is *not* * implemented by ' Hello-jni '. This was simply to show that * you can declare as many native methods in your Java code * as you want, their implem     entation is searched in the * currently loaded native libraries only the first time * you are call them.     * * Trying to call this function would result in a * Java.lang.UnsatisfiedLinkError exception! */     Public nativeString Unimplementedstringfromjni (); /*This was used to load the ' Hello-jni ' Library on application * startup.  The library has already been unpacked to */data/data/com.example.hellojni/lib/libhello-jni.so at * installation     Time by the package manager. */    Static{system.loadlibrary ("HelloJni1"); }

4) Use Javah to generate JNI header files in command line mode and create C or C + + implementation files;

Javah-jni-d JNI-CP Bin/classes:android-20.jar  Com.example.hellojni.HelloJni

5) Create android.mk, application.mk edit scripts in the JNI directory

#Android. Mklocal_path: = $ (call My-dir) include $ (clear_vars) local_module    : = hello-jnilocal_src_files: = Hello-jni.clocal_ldlibs    : =-lloginclude $ (build_shared_library)
#Application. Mkapp_abi: = All

6) Modify the Androidmanifest.xml file and follow the Hellojni to add the activity configuration item initiated by the project.

7) Eclipse starts debug as ... For debugging.

  

One of the Android NDK debugging methods: ADB Logcat

Related Article

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.