Android-jni adding standard C + + files

Source: Internet
Author: User

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

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.