- Create a JNI folder under the Eclipse Engineering directory.
- Create the ANDROID.MK and application.mk files in the Jni folder.
ANDROID.MK file:
An makefile file provided by Android that specifies such things as compiling generated so library names, referenced header file directories,. c/.cpp files that need to be compiled, and. A static library files. See the ANDROID.MK in the attachment.
APPLICATION.MK file:
Defines some details of the project, such as App_abi: = x86 (compile X86 Platform library), App_platform: = android-9 (using the Platform library above android-9).
- Use the CD command to move to the JNI directory, run the/mnt/500g/public/ndk/android-ndk-r7b/ndk-build command, the command line may be a compile error, such as the header file can not be found, function can not find and so on, look for a careful to get rid of.
- After the compilation is successful, you will generate the. So library in the libs/x86 in the project directory.
NDK compiles and uses static libraries, dynamic libraries
Scenario One: Compiling a static library
Scenario Two: Compiling a dynamic library
Scenario Three: Compiling dynamic libraries + static libraries
Scenario Four: There are third-party static libraries (dynamic libraries), compiling static libraries (dynamic libraries)
Default all code and files under $project/jni, otherwise special instructions.
Scenario One: Compiling a static library
File android.mk:
Local_path: = $ (call My-dir)
Include $ (clear_vars)
Local_module: = Hello-jni
Local_src_files: = Hello-jni.c
Include $ (build_static_library)
File application.mk:
app_modules : =hello-jni
Scenario Two: Compiling a dynamic library
File android.mk:
Local_path: = $ (call My-dir)
Include $ (clear_vars)
Local_module: = Hello-jni
Local_src_files: = Hello-jni.c
Include $ (build_shared_library)
Scenario Three: Compiling dynamic libraries + static libraries
File android.mk:
Local_path: = $ (call My-dir)
Include $ (clear_vars)
Local_module: = mylib_static
Local_src_files: = src.c
Include $ (build_static_library)
Include $ (clear_vars)
Local_module: = mylib_shared
Local_src_files: = src2.c
local_static_libraries : = mylib_static
Include $ (build_shared_library)
Scenario Four: There are third-party static libraries (dynamic libraries), compiling static libraries (dynamic libraries)
File android.mk:
Local_path: = $ (call My-dir)
Include $ (clear_vars)
Local_module: = thirdlib1 # name it whatever
Local_src_files: = $ (target_arch_abi)/libthird1.a # or $ (so_path)/libthird1.so
#LOCAL_EXPORT_C_INCLUDES: = $ (Local_path)/include
Include $ (prebuilt_static_library) #or prebuilt_shared_library
Include $ (clear_vars)
Local_module: = Mylib_use_thirdlib
Local_src_files: = src.c
local_static_libraries : = thirdlib1 #or local_shared_library
Include $ (build_shared_library) #如果编译静态库 and need to application.mk