The Android NDK Hello World

Source: Internet
Author: User

First write the JNI interface C file, this file name is special, the specific naming method can refer to the document to do.

#include <jni.h><string.h><stdio.h>*env, Jobject obj) {     return " 11111 ");}

Configure ANDROID.MK

#定义本地路径变量 Local_pathlocal_path: = $ (call My-dir) include $ (clear_vars) Local_module: = Native-liblocal_src_files: = Native-lib.cinclude $ (build_shared_library)

Once the Mk file is configured, execute the ndk-build in the JNI directory to get the so file for all current CPU platforms. After you import the so file into your project, write the code for the Java layer.

Java Code

@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);    Setcontentview (R.layout.activity_main); //Example of a call to a native methodTextView TV =(TextView) Findviewbyid (R.id.sample_text);    Tv.settext (Displayhelloworld ()); }    /*** A Native method that's implemented by the ' native-lib ' native library, * which are packaged with this appli     cation. */     Public nativeString Displayhelloworld (); //used to load the ' Native-lib ' Library on application startup.    Static{system.loadlibrary ("Native-lib"); }

After writing, execution can see 11111 of the content output on the screen on the real machine. At this point, the NDK's Hello World learning is over, and subsequent understanding of other NDK projects can be based on this idea to do the corresponding understanding and adjustment.

The Android NDK Hello World

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.