1, need to prepare tools, ECLIPSE,CDT (c + +) plug-ins, Cygwin (Unix) and Android NDK.
2. Development steps:
Public native String Hellofromjni (); generates a method signature for JNI by Javah the name of the package. C. Create a JNI directory, write C code, and the method name corresponds. or copy the generated signature file to the JNI directory and then introduce it in C code. D. Write the Android.mk file E.ndk compile the Build Dynamic library (ndk-build) F.java code load Dynamic Library. Calling native code
To create the Android.mk file, you need to replace the HELLO-JNI with your own C file module name:
Local_path: = $ (call my-dir) include $ (clear_vars) local_module := hello-jnilocal_src_files:= hello-Jni.cinclude $ (build_shared_library)
android.mk File Additions Local_ldlibs + =- Llog
C Add in Code
#include <android/ log.h >
#define Log_tag " System.out "
#define logd (...) __ Android_log_print (Android_log_debug, Log_tag, __va_args__)
#define Logi (...) __ Android_log_print (Android_log_info, Log_tag, __va_args__)
logi ("info\n");
logd ("debug\n");
jstring Java_cn_itcast_ndk_demoactivity_hellofromjni (jnienv *env, jobjectjavathis) {
return (*env)-newstringutf( Env , "Hello from native code!");
}
jnienv type represents the Java environment through jnienv * Pointers , will be able to Java end of the code to operate .
Create Java object of the class , called Java methods of the object
Get Java object Properties, and so on. .
Jobject What is it?
Jobject obj is the object represented by the class in which the current method resides .