1. Suppose the project name is ProjTest, first create a ProjTest folder, and then create two new directories in the ProjTest directory: jni and lib, the final result is as follows:
ProjTest
|----jni
|----libs
2. Add your C/C++ code to the jni directory. The C code used for the test here is as follows:
test.c
#include <stdio.h> #include <stdlib.h> intmain() { printf("Hello World\n"); return 0; }
3. Create and edit the Android.mk file in the jni directory. There is only one c code file: test.c, and the corresponding Android.mk is as follows:
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) # give module name LOCAL_MODULE := hello_world # list your C files to compile LOCAL_SRC_FILES := test.c # this option will build executables instead of building library for android application. include $(BUILD_EXECUTABLE)
Because our C code here is an executable program, the configuration is BUILD_EXECUTABLE ,
If it is a static library *.a file, use BUILD_STATIC_LIBRARY
If it is a dynamic link library *.so file, use BUILD_SHARED_LIBRARY
For detailed configuration of Android.mk, see: http://aigo.iteye.com/blog/2288694
4. Finally, switch the command line to the ProjTest/jni directory, assuming you have set the ndk environment variables, and then execute the command: ndk-build
Reference from: https://rathodpratik.wordpress.com/2013/03/24/build-cc-executables-for-android-using-ndk/