JNI joins standard C + + files
This address: Http://blog.csdn.net/caroline_wendy
Other references: http://blog.csdn.net/caroline_wendy/article/details/39032551
If you need to invoke the standard C + + library , you need to add the application.mk method under the JNI directory .
A Standard Template Library (STL) that declares the use of C + +: app_stl: = gnustl_static
App_stl: = gnustl_staticapp_cppflags: =-frtti-fexceptions#app_abi: = armeabi-v7a
then create the
add C + + source file and header file ,
declared in Android.mk .
header file is the directory path (the same directory can be omitted), the source file is the CPP file address , note is "+ =", indicating that is to continue to join
#LOCAL_C_INCLUDES + =/local_src_files + =/sayname.cpp
android.mk detailed files:
Local_path: = $ (call My-dir) include $ (clear_vars) local_module : = hellomyjnilocal_src_files: = hellomyjni.cpp# Local_c_includes + =/local_src_files + =/sayname.cppinclude $ (build_shared_library)
header file and source file contents:
/* * sayname.h * * Created on:2014 September 4 * author:administrator * * #ifndef sayname_h_#define sayname_h_#include &L T;string>using namespace std;string sayname (void); #endif/* Sayname_h_ *//* * sayname.cpp * * Created on:2014 Year September 4 * Author:administrator */#include "sayname.h" string sayname (void) {string str = "Hello Spike and Caroline and wendy! !!"; return str;}
The interface files will be able to invoke these standard C + + files.
Detailed Invocation Method:
#include <jni.h> #include "com_example_hellomyjni_jniclient.h" #include "sayname.h" Jniexport jstring Jnicall Java_com_example_hellomyjni_jniclient_sayname (jnienv *env, jclass) {string str = Sayname (); return env-> Newstringutf (Str.c_str ());}
Android-jni adding standard C + + files