JNI support for C + + and C differences

Source: Internet
Author: User

1. The code suffix for C + + is ". cpp"

2. There are two sets of code in the JNI.h file. One is to support C, and the other is to support JNI.

Jni. H Address:mac? user? Douj? Documents? ANDROID-NDK-R10B? Platforms? Android-8?

The code for C in JNI is:

Jstring (*newstringutf) (jnienv*, const Char*);

C in Call mode:

(*env)->newstringutf (env,"haha from c");

The code for C + + in JNI is:

jstring newstringutf (const char* bytes)

{ return Functions->newstringutf (this, bytes);}

How to call in C + +

jniexport jstring jnicall java_cn_itcast_cpp_demoactivity_helloinc   * env, Jobject obj) {     return      env->newstringutf ("haha from c" );}

3. Modify the Android.mk file

  Local_path: = $ (call My-dir)   include $ (clear_vars)   #针对C + + support, tag C + + file extension name   local_cpp_extension: = CPP      #打的包模块名称. The Libhello.so library is generated based on this.   local_module    : = Hello   local_src_files: = Hello.cpp #需要编译的相关C, C + + code   # Log Support   Local_ldlibs + =- Llog   include $ (build_shared_library)

4. Advantages of C + +

The function parameter names that are not required can be unnamed parameters.

JNI support for C + + and C differences

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.