Source: Android Ndk compile (import). A file and compile multiple so files
first, 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 := fpdfembedsdklocal_src_files:= xxxx.cpplocal_c_includes:= $ (local_path)/... /include/local_ldlibs:=-llog-g-L-in + = libstatic_ Android.alocal_static_libraries:= static_androidinclude $ (build_shared_library) #$ (build_static_ LIBRARY)
Second, compiling multiple so files
(1) The Android.mk file first needs to specify the Local_path variable, which is used to locate the source file. since android.mk and the source files that need to be compiled are in the same directory, they are defined in the following form:
The statement above local_path:=$ (call My-dir) means that the Local_path variable is defined as the directory path where the cost file is located.
(2) ANDROID.MK can define multiple compilation modules , each compiled module starts with the include $ (clear_vars) and ends with the include $ (build_xxx). Include $ (clear_vars) Clear_vars is provided by the compilation system, specifying that the GNU makefile for you to clear all local_xxx variables except Local_path, such as Local_module,local_src_ Files,local_shared_libraries,local_static_libraries and so on.
The include $ (build_static_library) means that compiling into a static library include $ (build_shared_library) means compiling into a dynamic library. Include $ (build_executable) to compile into executable program
(3) Examples are as follows (FRAMEWORKS/BASE/LIBS/AUDIOFLINGER/ANDROID.MK):
Local_path:= $ (Call my-dir) include $ (clear_vars) module one ifeq ($ (audio_policy_test),true) Enable_audio_dump:=trueendif local_src_files:=AudioHardwareGeneric.cpp AudioHardwareStub.cpp AudioHardwareInterface.cpp ifeq ($ (enable_audio_dump), /c4>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 one compiled into static library include $ (clear_vars) module two local_src_files:=AudioPolicyManagerBase.cpp local_shared_libraries:=libcutils libutils Libmedia ifeq ($ (target_simulator),true) Local_ldlibs+= -LDLElselocal_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 two compiled into static library include $ (clear_vars) module three 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_audioElselocal_shared_libraries+=libaudio libaudiopolicy endif ifeq ($ (target_simulator),true) Local_ldlibs+= -LDLElselocal_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 three compiled into a dynamic library
(4) Compiling an application (APK)
Local_path: = $ (call my-dir) include $ (clear_vars) in the Java subdirectory--> Literal translation (all Java files built into the Java subdirectory) local_src_files:= $ (call all-subdir-java-FILES) # Name of the APK to build
--> literal translation (create the name of the APK) local_package_name:= localpackage # Tell it to build a apk- literal translation (Tell it to build an APK) include $ (build_package)
(5) Compiling an application that relies on a static Java library (Static.jar)
Local_path: = $ (call my-dir) include $ (clear_vars) static in the package Local_static_java_libraries:STATIC-library 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) Compiling an application that requires a platform key signature
Local_path: = $ (call my-dir) include $ (clear_vars) in the java subdirectory Local_ Src_files:= $ (call all-subdir-java-FILES) # Name of the APK to build local_package_name:= Lo Calpackage local_certificate:= Platform # Tell it to build an APK include $ (build_package)
(7) Compiling an application that needs to be preceded by a specific key
Local_path: = $ (call my-dir) include $ (clear_vars) in the java subdirectory Local_ Src_files:= $ (call all-subdir-java-FILES) # Name of the APK to build local_package_name:= Lo Calpackage local_certificate:= vendor/example/certs/app # Tell it to build an APK include $ ( Build_package)
(8) Add a precompiled application
Local_path: = $ (call my-dir) include $ (clear_vars) # Module name should match apk name to be installed. Local_module:= localmodulename local_src_files:= $ (local_module). 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) in the java subdirectory Local_ Src_files:= $ (call all-subdir-java-FILES) this library depends on Local_java_ LIBRARIES:= Android.test.runner # The name of the jar file to create local_module:= Samp Le static jar file.
(10) In the middle of the android.mk compile module, you can define the relevant compilation content, that is, specify the relevant variables as follows:
local_aapt_flagslocal_acp_unavailable Local_additional_java_dir local_aidl_includes LOCAL_ALLOW_UNDEFINED_ SYMBOLS local_arm_mode local_asflags local_asset_dir local_asset_files Set this variable when compiling the application (ANDROID.MK) in the Build_package file. Represents a resource file, which is typically defined as a local_asset_files+ = $ (call find-subdir-assets) Local_built_module_stem local_c_includes Extra C/c++compile the header file path, and use Local_path to indicate the directory where this file is located: Local_c_includes+ = extlibs/zlib-1.2.3Local_c_includes+ = $ (local_path)/src local_cc specifies C compiler local_certificate signature authentication local_cflags to C/c++ compiler defines additional flags (such as macro definitions), for example: Local_cflags + =-dlibutils_native=1local_classpath local_compress_module_symbols local_copy_headers The header file that needs to be copied when you install the application, you must also define Local_copy_ Headers_to local_copy_headers_to Install application when copying the destination path of the header file local_cpp_extension if your C+ + files are not file suffixes with CPP, you can specify C + + by local_cpp_extensionfile suffix name such as: local_cpp_extension:=. CC Note In the Unified module C++The file suffix must remain consistent. Local_cppflags Pass the extra flag to C+ + compiler, such as: Local_cppflags + =-ffriend-injection Local_cxx Specify C++compiler Local_dx_flags Local_export_package_resources local_force_static_executable If the compiled executable is to be statically linked (execution is not dependent on any dynamic library ), set the local_force_static_executable:=truecurrently only libc has a static library form, which is only available in the file system/applications in the Sbin directory are used, and applications in this directory are normally not loaded in other parts of the file system at runtime, 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 When compiling Java applications and libraries, you specify the Java class libraries that are included, which are currently defined in the core and framework two in most cases: local_java_libraries:=The core framework notes that local_java_libraries is not required and is not allowed to be defined when compiling the APK (the system will automatically add it) Local_java_resource_dirs LOCAL _java_resource_files local_jni_shared_libraries local_ldflags Pass additional parameters to the connector (be sure to note the order of the parameters) Local_ldlibs Specify an additional library for the compilation of the executable or library, specifying the library to"-lxxx"format, example: Local_ldlibs+ =-lcurses-Lpthread local_ldlibs+ =-wl,-Z,origin Local_module The name of the generated module (note that the application name is Local_package_name instead of Local_module) Local_module_path the path of the build module Local_module_ STEM local_module_tags Generation Module Markup Local_no_default_compiler_flags local_no_emma_compile local_no_emma_instrument LOCAL_ No_standard_libraries local_overrides_packages local_package_name apk app name Local_post_process_command LOCAL_ Prebuilt_executables precompiled including $ (build_prebuilt) or $ (build_host_prebuilt), specifies the executable file that needs to be copied Local_prebuilt_java_ LIBRARIES Local_prebuilt_libs precompiled including $ (build_prebuilt) or $ (build_host_prebuilt), specify the libraries that need to be copied. Local_prebuilt_obj_files local_prebuilt_static_java_libraries Local_prelink_module Whether pre-connection processing is required (default is required for Dynamic library optimization) LOCAL_ Required_modules specifies the module on which the module is to be run (the module to which it depends will be installed synchronously when the module is mounted) Local_resource_dir local_sdk_version local_shared_libraries can link dynamic library local_src_files compile source file local_static_java_libraries local_static_libraries can link static library Local_uninstallable_module Local_unstripped_path local_whole_static_libraries Specifies the full static library required for the module to be loaded (these mastering libraries do not allow the linker to delete the useless code in the link) local_yaccflaGS Override_built_module_path
Android NDK compile (import). A file and compile multiple so files (go)