Android Learning note _jni Hello World

Source: Internet
Author: User

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 .

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.