Android Graphics and text introduction NDK installation and implementation of simple JNI Demon

Source: Internet
Author: User

1. Background

The Android NDK can be used to compile the native method of Android, and C and C + + code can be compiled into the. so file, allowing the Android program to run.

2.NDK installation (Linux environment)

(1) Download the corresponding NDK version, enter the following command in the shell

Gedit ~/.BASHRC

(2) Open bash file, add download NDK path

ndkroot=/home/corpusers/28852262/android-ndk-r9c  
export path= $NDKROOT: $PATH

(3) Enter the following command, and then restart the shell

Source/etc/profile

(4) Enter Ndk-build in the shell, and the following status indicates that the installation was successful

3.jni First Demon HelloWorld

(1) Writing HELLO-JNI.C documents.

#include <string.h>  
#include <jni.h>/  
      
* A trivial JNI example where we use a native method
  
   * to return a new VM String. The corresponding Java source  
 * file located at:  
 *  
 *   apps/samples/hello-jni/project/src/com/ Example/hellojni/hellojni.java  
 * *  
jstring  
java_com_example_hellojni_hellojni_aa (jnienv* env,  
                                                  Jobject thiz)  
{  
#if defined (__arm__)  
  #if defined (__arm_arch_7a__)  
    #if defined (__arm_neon__)  
      #define ABI "Armeabi-v7a/neon"  
    #else  
      #define ABI "armeabi-v7a"  
    #endif  
  #else  
   #define Abi "Armeabi"  
  #endif  
#elif defined (__i386__)  
   #define ABI "x86"  
#elif defined (__mips__)  
   # Define ABI "MIPS"  
#else  
   #define ABI "Unknown"  
#endif return  
      
    (*env)->newstringutf (env, "Hello From JNI!  Compiled with Abi "ABI" ");  

  

This c file implements output A string function, note here

Java_com_example_hellojni_hellojni_aa

When we created the Android application, the package and function names were to correspond to this, otherwise the report was wrong: Native method isn't found. The following figure

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/

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.