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