And Roid to compile your own library file jar and call it in the application

Source: Internet
Author: User

 

The MAKEFILE file Android. mk of the android compilation system is written as follows:

(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, so it 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 ).
End 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

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.