Simple steps for Android to invoke JNI

Source: Internet
Author: User

1. Cross-compiling files under Linux are mainly in. elf format files executed under window are. EXE JNI is the link between the two Google offers a tool-ndk

2. Step:  1. In Java, define the method public native String SayHello ();              &NBSP;2. Create a JNI folder in your project and create a hello.c file where you write C code;               3.   First declaration #include <stdio.h>                      #include < stdlib.h>                    #include <jni.h>//jobject jobj who called the This method refers to who   is currently mainactivity.this                     jstring Java_com_andson_jnihellodemo_mainactivity_sayhello (jnienv* env,jobject jobj) {}               4. Create and write Android.mk (create associated file) (labeled C file and library file) file in ADT file                5. Run cmd ndk-build (compile)               &NBSP;6 in the project file. Load the dynamic-link library system.loadlibrary ("Andson") before calling the method in Java; Note: 3. As long as the C code changes need to be recompiled; 4. If there is an underscore in the Java method   You need to add  1 in C code; You can also use the Javah method to generate the header file 5. What is supported to run the system is to see if at the time of compiling the Application.mk file to choose whether the relevant system 6. Android tool Add native surpport change file to C    

Simple steps for Android to invoke JNI

Related Article

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.