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/