Android Development NDK compiles and uses static libraries, dynamic libraries

Source: Internet
Author: User

    1. Create a JNI folder under the Eclipse Engineering directory.
    2. 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).

    1. 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.
    2. 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

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.