Android ndk compilation and use of static and dynamic libraries

Source: Internet
Author: User

 

 

Ndk compiles and uses static and dynamic libraries

Case 1: Compile the static library

Case 2: Compile the dynamic library

Case 3: Compile the dynamic library + static library

Scenario 4: existing third-party static libraries (dynamic libraries), compiling static libraries (dynamic libraries)

 

By default, all codes and files are under $ Project/JNI. Otherwise, special instructions are provided.

Case 1: Compile the 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

 

Case 2: Compile the 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)

Case 3: Compile the dynamic library + static library

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 4: existing 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) # OrPrebuilt _Shared_ Library

Include $ (clear_vars)
Local_module: = mylib_use_thirdlib
Local_src_files: = SRC. c

Local_static_libraries: = Thirdlib1 # OrLocal_Shared_ Library

Include $ (Build_shared_library) # If a static library is compiled, application. mk is required.

 

Related Article

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.