Android NDK compilation (import). a file and multiple so files

Source: Internet
Author: User

1. Compile a static library libstatic_android.a


LOCAL_PATH: = $ (call my-dir)

Include $ (CLEAR_VARS)
LOCAL_MODULE: = static_android
LOCAL_SRC_FILES: = libstatic_android.a
Include $ (PREBUILT_STATIC_LIBRARY)

Include $ (CLEAR_VARS)
LOCAL_MODULE: = fpdfembedsdk
LOCAL_SRC_FILES: = xxxx. cpp
LOCAL_C_INCLUDES: = $ (LOCAL_PATH)/../include/
LOCAL_LDLIBS: =-llog-g-L.-ljnigraphics

# Fill in the foxit library here
# LOCAL_LDLIBS + = libstatic_android.a
LOCAL_STATIC_LIBRARIES: = static_android
Include $ (BUILD_SHARED_LIBRARY) # $ (BUILD_STATIC_LIBRARY)

 


2. Compile multiple so files

 

(1) In the Android. mk file, you must specify the LOCAL_PATH variable to find the source file. Generally, Android. mk is in the same directory as the source file to be compiled, and is defined as follows:

LOCAL_PATH: = $ (call my-dir)
The preceding statement defines the LOCAL_PATH variable as the directory path of the cost file.
(2) Multiple compilation modules can be defined in Android. mk. Each compilation module starts with include $ (CLEAR_VARS) and ends with include $ (BUILD_XXX.
Include $ (CLEAR_VARS)
CLEAR_VARS is provided by the compilation system, specifying that gnu makefile will clear all LOCAL_XXX variables except LOCAL_PATH for you,
For example, LOCAL_MODULE, LOCAL_SRC_FILES, LOCAL_SHARED_LIBRARIES, and LOCAL_STATIC_LIBRARIES.

Include $ (BUILD_STATIC_LIBRARY) indicates compiling to a static library
Include $ (BUILD_SHARED_LIBRARY) indicates compiling to a dynamic library.
Include $ (BUILD_EXECUTABLE) indicates compiling into executable programs

(3) Example (frameworks/base/libs/audioflinger/Android. mk ):

LOCAL_PATH: = $ (call my-dir)
Include $ (CLEAR_VARS) Module 1
Ifeq ($ (AUDIO_POLICY_TEST), true)
ENABLE_AUDIO_DUMP: = true
Endif

LOCAL_SRC_FILES: = \
AudioHardwareGeneric. cpp \
AudioHardwareStub. cpp \
AudioHardwareInterface. cpp
Ifeq ($ (ENABLE_AUDIO_DUMP), true)
LOCAL_SRC_FILES + = AudioDumpInterface. cpp
LOCAL_CFLAGS + =-DENABLE_AUDIO_DUMP
Endif

LOCAL_SHARED_LIBRARIES: = \
Libcutils \
Libutils \
Libbinder \
Libmedia \
Libhardware_legacy

Ifeq ($ (strip $ (BOARD_USES_GENERIC_AUDIO), true)
LOCAL_CFLAGS + =-DGENERIC_AUDIO
Endif

LOCAL_MODULE: = libaudiointerface

Ifeq ($ (BOARD_HAVE_BLUETOOTH), true)
LOCAL_SRC_FILES + = A2dpAudioInterface. cpp
LOCAL_SHARED_LIBRARIES + = liba2dp
LOCAL_CFLAGS + =-DWITH_BLUETOOTH-DWITH_A2DP
LOCAL_C_INCLUDES + = $ (call include-path-for, bluez)
Endif

Include $ (BUILD_STATIC_LIBRARY) Module 1 is compiled into a static library

Include $ (CLEAR_VARS) Module 2
LOCAL_SRC_FILES: = \
AudioPolicyManagerBase. cpp
LOCAL_SHARED_LIBRARIES: = \
Libcutils \
Libutils \
Libmedia

Ifeq ($ (TARGET_SIMULATOR), true)
LOCAL_LDLIBS + =-ldl
Else
LOCAL_SHARED_LIBRARIES + = libdl
Endif

LOCAL_MODULE: = libaudiopolicybase
Ifeq ($ (BOARD_HAVE_BLUETOOTH), true)
LOCAL_CFLAGS + =-DWITH_A2DP
Endif

Ifeq ($ (AUDIO_POLICY_TEST), true)
LOCAL_CFLAGS + =-DAUDIO_POLICY_TEST
Endif

Include $ (BUILD_STATIC_LIBRARY) Module 2 is compiled into a static library

Include $ (CLEAR_VARS) Module 3
LOCAL_SRC_FILES: = \
AudioFlinger. cpp \
AudioMixer. cpp. arm \
AudioResampler. cpp. arm \
AudioResamplerSinc. cpp. arm \
AudioResamplerCubic. cpp. arm \
AudioPolicyService. cpp
LOCAL_SHARED_LIBRARIES: = \
Libcutils \
Libutils \
Libbinder \
Libmedia \
Libhardware_legacy
Ifeq ($ (strip $ (BOARD_USES_GENERIC_AUDIO), true)
LOCAL_STATIC_LIBRARIES + = libaudiointerface libaudiopolicybase
LOCAL_CFLAGS + =-DGENERIC_AUDIO
Else
LOCAL_SHARED_LIBRARIES + = libaudio libaudiopolicy
Endif

Ifeq ($ (TARGET_SIMULATOR), true)
LOCAL_LDLIBS + =-ldl
Else
LOCAL_SHARED_LIBRARIES + = libdl
Endif

LOCAL_MODULE: = libaudioflinger
Ifeq ($ (BOARD_HAVE_BLUETOOTH), true)
LOCAL_CFLAGS + =-DWITH_BLUETOOTH-DWITH_A2DP
LOCAL_SHARED_LIBRARIES + = liba2dp
Endif

Ifeq ($ (AUDIO_POLICY_TEST), true)
LOCAL_CFLAGS + =-DAUDIO_POLICY_TEST
Endif

Ifeq ($ (TARGET_SIMULATOR), true)
Ifeq ($ (HOST_ OS), linux)
LOCAL_LDLIBS + =-lrt-lpthread
Endif
Endif

Ifeq ($ (BOARD_USE_LVMX), true)
LOCAL_CFLAGS + =-DLVMX
LOCAL_C_INCLUDES + = vendor/nxp
LOCAL_STATIC_LIBRARIES + = liblifevibes
LOCAL_SHARED_LIBRARIES + = liblvmxservice
# LOCAL_SHARED_LIBRARIES + = liblvmxipc
Endif

Include $ (BUILD_SHARED_LIBRARY) Module 3 is compiled into a dynamic library

(4) Compile an application (APK)

LOCAL_PATH: = $ (call my-dir)
Include $ (CLEAR_VARS)
# Build all java files in the java subdirectory --> literal translation (all java files created in the Java subdirectory)
LOCAL_SRC_FILES: = $ (call all-subdir-java-files)
# Name of the APK to build --> literal translation (Name of the created APK)
LOCAL_PACKAGE_NAME: = LocalPackage
# Tell it to build an APK --> (Tell it to build an APK)
Include $ (BUILD_PACKAGE)

(5) Compile an application dependent on the static Java Library (static. jar)

LOCAL_PATH: = $ (call my-dir)
Include $ (CLEAR_VARS)
# List of static libraries to include in the package
LOCAL_STATIC_JAVA_LIBRARIES: = static-library
# Build all java files in the java subdirectory
LOCAL_SRC_FILES: = $ (call all-subdir-java-files)
# Name of the APK to build
LOCAL_PACKAGE_NAME: = LocalPackage
# Tell it to build an APK
Include $ (BUILD_PACKAGE)

(6) Compile an application that requires the signature of the platform key.

LOCAL_PATH: = $ (call my-dir)
Include $ (CLEAR_VARS)
# Build all java files in the java subdirectory
LOCAL_SRC_FILES: = $ (call all-subdir-java-files)
# Name of the APK to build
LOCAL_PACKAGE_NAME: = LocalPackage
LOCAL_CERTIFICATE: = platform
# Tell it to build an APK
Include $ (BUILD_PACKAGE)

(7) Compile an application that requires a specific key.

LOCAL_PATH: = $ (call my-dir)
Include $ (CLEAR_VARS)
# Build all java files in the java subdirectory
LOCAL_SRC_FILES: = $ (call all-subdir-java-files)
# Name of the APK to build
LOCAL_PACKAGE_NAME: = LocalPackage
LOCAL_CERTIFICATE: = vendor/example/certs/app
# Tell it to build an APK
Include $ (BUILD_PACKAGE)

(8) Add a pre-compiled Application

LOCAL_PATH: = $ (call my-dir)
Include $ (CLEAR_VARS)
# Module name shoshould match apk name to be installed.
LOCAL_MODULE: = LocalModuleName
LOCAL_SRC_FILES: = ((local_moduleapps.apk
LOCAL_MODULE_CLASS: = APPS
LOCAL_MODULE_SUFFIX: = $ (COMMON_ANDROID_PACKAGE_SUFFIX)
Include $ (BUILD_PREBUILT)

(9) Add a static JAVA Library

LOCAL_PATH: = $ (call my-dir)
Include $ (CLEAR_VARS)
# Build all java files in the java subdirectory
LOCAL_SRC_FILES: = $ (call all-subdir-java-files)
# Any libraries that this library depends on
LOCAL_JAVA_LIBRARIES: = android. test. runner
# The name of the jar file to create
LOCAL_MODULE: = sample
# Build a static jar file.
Include $ (BUILD_STATIC_JAVA_LIBRARY)
(10) The compilation module of Android. mk can define the relevant compilation content, that is, specify the relevant variables as follows:

LOCAL_AAPT_FLAGS
LOCAL_ACP_UNAVAILABLE
LOCAL_ADDITIONAL_JAVA_DIR
Local_aidl_regiondes
LOCAL_ALLOW_UNDEFINED_SYMBOLS
LOCAL_ARM_MODE
LOCAL_ASFLAGS
LOCAL_ASSET_DIR
LOCAL_ASSET_FILES sets this variable when compiling the application (BUILD_PACKAGE) in the Android. mk file, which indicates the resource file,
It is usually defined as LOCAL_ASSET_FILES + = $ (call find-subdir-assets)
LOCAL_BUILT_MODULE_STEM
LOCAL_C_INCLUDES: the path of the header file for compiling C/C ++. Use LOCAL_PATH to indicate the directory of the file.
Example:
LOCAL_C_INCLUDES + = extlibs/zlib-1.2.3
LOCAL_C_INCLUDES + = $ (LOCAL_PATH)/src
LOCAL_CC specifies the C Compiler
LOCAL_CERTIFICATE signature authentication
LOCAL_CFLAGS defines additional flag (such as macro definition) for the C/C ++ compiler. For example: LOCAL_CFLAGS + =-DLIBUTILS_NATIVE = 1
LOCAL_CLASSPATH
LOCAL_COMPRESS_MODULE_SYMBOLS
The header file to be copied when LOCAL_COPY_HEADERS install the application. LOCAL_COPY_HEADERS_TO must be defined at the same time.
LOCAL_COPY_HEADERS_TO the destination path for copying the header file when installing the application
LOCAL_CPP_EXTENSION if your C ++ file is not suffixed with cpp, you can use LOCAL_CPP_EXTENSION to specify the suffix of the C ++ file.
For example: LOCAL_CPP_EXTENSION: =. cc
Note that the C ++ file suffixes must be consistent in the Unified Module.
LOCAL_CPPFLAGS transmits additional flags to the C ++ compiler, such as: LOCAL_CPPFLAGS + =-ffriend-injection
LOCAL_CXX specifies the C ++ Compiler
LOCAL_DX_FLAGS
LOCAL_EXPORT_PACKAGE_RESOURCES
LOCAL_FORCE_STATIC_EXECUTABLE if the compiled executable program requires a static Link (the execution does not depend on any dynamic library), set LOCAL_FORCE_STATIC_EXECUTABLE: = true
Currently, only libc has a static library, which is only used by applications in the/sbin directory of the file system.
Other parts of the file system have not been loaded, so static links must be made.
LOCAL_GENERATED_SOURCES
LOCAL_INSTRUMENTATION_FOR
LOCAL_INSTRUMENTATION_FOR_PACKAGE_NAME
LOCAL_INTERMEDIATE_SOURCES
LOCAL_INTERMEDIATE_TARGETS
LOCAL_IS_HOST_MODULE
LOCAL_JAR_MANIFEST
LOCAL_JARJAR_RULES
LOCAL_JAVA_LIBRARIES specifies the included java class library when compiling java applications and libraries. Currently, there are two types: core and framework.
In most cases, it is defined as: LOCAL_JAVA_LIBRARIES: = core framework
Note: LOCAL_JAVA_LIBRARIES is not mandatory and cannot be defined during APK compilation (automatically added)
LOCAL_JAVA_RESOURCE_DIRS
LOCAL_JAVA_RESOURCE_FILES
LOCAL_JNI_SHARED_LIBRARIES
LOCAL_LDFLAGS pass additional parameters to the connector (note the order of parameters)
LOCAL_LDLIBS specifies an additional library for compilation of executable programs or libraries. The specified library is in the "-lxxx" format. For example:
LOCAL_LDLIBS + =-lcurses-lpthread
LOCAL_LDLIBS + =-Wl,-z, origin
Name of the module generated by LOCAL_MODULE (note that the Application name is LOCAL_PACKAGE_NAME instead of LOCAL_MODULE)
Path of the module generated by LOCAL_MODULE_PATH
LOCAL_MODULE_STEM
Mark of the module generated by LOCAL_MODULE_TAGS
LOCAL_NO_DEFAULT_COMPILER_FLAGS
LOCAL_NO_EMMA_COMPILE
LOCAL_NO_EMMA_INSTRUMENT
LOCAL_NO_STANDARD_LIBRARIES
LOCAL_OVERRIDES_PACKAGES
LOCAL_PACKAGE_NAME The Name Of The APK Application
LOCAL_POST_PROCESS_COMMAND
LOCAL_PREBUILT_EXECUTABLES used to pre-compile including $ (BUILD_PREBUILT) or $ (BUILD_HOST_PREBUILT), specify the executable file to be copied
LOCAL_PREBUILT_JAVA_LIBRARIES
LOCAL_PREBUILT_LIBS used to pre-compile including $ (BUILD_PREBUILT) or $ (BUILD_HOST_PREBUILT), specifying the database to be copied.
LOCAL_PREBUILT_OBJ_FILES
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES
LOCAL_PRELINK_MODULE requires pre-connection processing (required by default for dynamic library optimization)
LOCAL_REQUIRED_MODULES specifies the module on which the module depends to run (the module will be installed synchronously during module installation)
LOCAL_RESOURCE_DIR
LOCAL_SDK_VERSION
LOCAL_SHARED_LIBRARIES can be used to link dynamic libraries.
LOCAL_SRC_FILES
LOCAL_STATIC_JAVA_LIBRARIES
LOCAL_STATIC_LIBRARIES can be linked to a static library
LOCAL_UNINSTALLABLE_MODULE
LOCAL_UNSTRIPPED_PATH
LOCAL_WHOLE_STATIC_LIBRARIES specifies the complete static library to be loaded by the module (these master libraries do not allow the linker to delete useless code in the Link)
LOCAL_YACCFLAGS
OVERRIDE_BUILT_MODULE_PATH

 

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.