Fuse: Android NDK R7 is integrated with Cywin and does not bother to download and configure Cywin when developing the NDK.
Android NDK Development Steps:
-
Eclipse first configures the NDK path, WINDOWS–>PREFERENCES–>ANDROID–>NDK, to specify the NDK path: for example: D:\AndroidNDK\ndk-r10e
If you do not see the NDK configuration option under Windows–preferences–>android, then download the ECLIPSE–NDK plugin: Http://pan.baidu.com/s/1dDXBKTN, I am Win7 x64 system , so please download the corresponding ECLIPSENDK plugin according to your system. Download the Xxxxxxxxxxxxndk.jar, copy the download, and put it in the Eclipse root directory, such as the D:\Androiddevelop\eclipse\plugins file, and restart Eclipse to see it.
-
New Android project named, Androidndkdemo, new package name Com.jni, new Jni.java, declaring the C method to be called in JNI.
-
Select Project, right click on Android tools–>add Native support ..., set up so library named Hello-jni.so. Click Finish.
At this point you will find in the project directory, a more JNI directory with the obj directory, the directory of two files are: Android.mk, with a hello.cpp file. I am here to replace the Hello.cpp file with the hello.c file directly.
-
CMD into D:\workspace\AndroidJniTest\bin\
Javah-jni Com.jni.JNI generates the Hello.h file. Reference
-
Compiles the associated hello.c file based on the generated. h file.
If you need to generate different specifications for different CPUs, you need to libhello.so in the hello.c file.
hello.c
jstring Java_com_patch_JNI_Hello(JNIEnv* env, jobject obj) {#if defined(__arm__)#if defined(__ARM_ARCH_7A__)#if defined(__ARM_NEON__)#if defined(__ARM_PCS_VFP)#define ABI "armeabi-v7a/NEON (hard-float)"#else#define ABI "armeabi-v7a/NEON"#endif#else#if defined(__ARM_PCS_VFP)#define ABI "armeabi-v7a (hard-float)"#else#define ABI "armeabi-v7a"#endif#endif#else#define ABI "armeabi"#endif#elif defined(__i386__)#define ABI "x86"#elif defined(__x86_64__)#define ABI "x86_64"#elif defined(__mips64) /* mips64el-* toolchain defines __mips__ too */#define ABI "mips64"#elif defined(__mips__)#define ABI "mips"#elif defined(__aarch64__)#define ABI "arm64-v8a"#else#define ABI "unknown"#endifreturn (*env)->NewStringUTF(env, "Yes ,Hello from JNI !");
}
Android.mk
# Copyright (C) 2009 The Android Open Source Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := hello-jni LOCAL_SRC_FILES := hello.c include $(BUILD_SHARED_LIBRARY)
Application.mk
Content:
APP_ABI := all
-
Call in activity:
-
Run, if the compilation succeeds you will find that the LIBS directory structure has changed
Effect:
Android NDK Development (note i)