LOCAL_SHARED_LIBRARIES := avilib ...
Building Standalone Executable
The recommended and supported way of using native components on Android platform is through packaging them as shared libraries. However, in order to facilitate testing and quick prototyping, Android NDK also provides support for building a standalone executable. The standalone
executables are regular Linux applications that can be copied to the Android device without being packaged into an APK file, and they can get executed directly without being loaded through a Java application. Standalone executables can be produced by importing the BUILD_EXECUTABLE variable in the Android.mk build file instead of BUILD_SHARED_LIBRARY, as shown in Listing 2-8.
Listing 2-8. Android.mk File for Standalone Executable Module
#
# Native module standlone executable
#
include $(CLEAR_VARS) LOCAL_MODULE := module LOCAL_SRC_FILES := module.c LOCAL_STATIC_LIBRARIES := avilib include $(BUILD_EXECUTABLE)
The BUILD_EXECUTABLE variable points to the build-executable.mk Makefile fragment that contains the necessary build steps to produce a standalone executable on Android platform. The standalone executable gets placed into libs/<machine architecture> directory with the same name as the module. Although it is placed into this directory, it does not get included into the APK file during the packaging phase.
Other Build System Variables
Besides the variables covered in the previous sections, there are other variables that are supported by the Android NDK build system. This section will briefly mention them.
The variables that are defined by the build system are
TARGET_ARCH: Name of the target CPU architecture, such as arm.
TARGET_PLATFORM: Name of the target Android platform, such as android-3.Download at http://www.pin5i.com/
TARGET_ARCH_ABI: Name of the target CPU architecture and the ABI, such as armeabi-v7a.
TARGET_ABI: Concatenation of target platform and ABI, such as android-3-armeabi-v7a.
The variables that can be defined as a part of the module description are
LOCAL_MODULE_FILENAME: Optional variable to redefine the name of the generated output file. By default the build system uses the value of LOCAL_MODULE as the name of the generated output file, but it can be overridden using this variable.
LOCAL_CPP_EXTENSION: The default extension of C++ source files is .cpp.
This variable can be used to specify one or more file extensions for the C++
source code.
...
LOCAL_CPP_EXTENSION := .cpp .cxx ...
LOCAL_CPP_FEATURES: Optional variable to indicate that the module relies on specific C++ features such as RTTI, exceptions, etc.
...
LOCAL_CPP_FEATURES := rtti ...
LOCAL_C_INCLUDES: Optional list of paths, relative to NDK installation directory, to search for header files.
...
LOCAL_C_INCLUDES := sources/shared-module LOCAL_C_INCLUDES := $(LOCAL_PATH)/include ...
LOCAL_CFLAGS: Optional set of compiler flags that will be passed to the compiler while compiling the C and C++ source files.
...
LOCAL_CFLAGS := − DNDEBUG –DPORT = 1234 ...
LOCAL_CPP_FLAGS: Optional set of compiled flags that will be passed to the compiler while compiling the C++ source files only.
LOCAL_WHOLE_STATIC_LIBRARIES: A variant of LOCAL_STATIC_LIBRARIES that indicates that the whole content of the static library should be included in the generated shared library.
Download at http://www.pin5i.com/
LOCAL_LDLIBS: Optional list of linker flags that will be passed to the linker while linking the object files to generate the output file. It is primarily used to pass the list of system libraries to dynamically link with. For example, to link with the Android NDK logging library, use this code:
LOCAL_LDFLAGS := − llog
LOCAL_ALLOW_UNDEFINED_SYMBOLS: Optionally disables the checking for missing symbols in the generated file. When not defined, the linker will produce error messages indicating the missing symbols.
LOCAL_ARM_MODE: Optional and ARM machine architecture-specific variable indicating the type of ARM binary to be generated. By default, the build system generates in thumb mode with 16-bit instructions, but this variable can be set to arm to indicate that the 32-bit instructions should be used.
LOCAL_ARM_MODE := arm
This variable changes the build system behavior for the entire module; the .arm extension can also be used to only build specific files in arm mode.
LOCAL_SRC_FILES := file1.c file2.c.arm
LOCAL_ARM_NEON: Optional and ARM machine architecture-specific variable indicating that ARM Advanced Single Instruction Multiple Date (SIMD) (a.k.a. NEON) intrinsics should be enabled in the source files.
LOCAL_ARM_NEON := true
This variable changes the build system behavior for the entire module; the .neon extension can also be used to only build specific files with NEON intrinsics.
LOCAL_SRC_FILES := file1.c file2.c.neon
LOCAL_DISABLE_NO_EXECUTE: Optional variable to disable the NX Bit security feature. NX Bit, which stands for Never Execute, is a technology used in CPUs to segregate areas of memory for use by either code or storage. This prevents malicious software from taking control of the application by inserting its code into the application’s storage memory area.
LOCAL_DISABLE_NO_EXECUTE := true
LOCAL_EXPORT_CFLAGS: This variable allows recording a set of compiler flags that will be added to the LOCAL_CFLAGS definition of any other module that is using this module through either LOCAL_STATIC_LIBRARIES or LOCAL_SHARED_LIBRARIES.
LOCAL_MODULE := avilib
Tip LOCAL_WHOLE_STATIC_LIBRARIES is very useful when there are circular dependencies between several static libraries.
Download at http://www.pin5i.com/
...
The compiler will get executed with flags –DENABLE_AUDIO –DDEBUG while building the module1.
LOCAL_EXPORT_CPPFLAGS: Same as the LOCAL_EXPORT_CLAGS but for C++
code-specific compiler flags.
LOCAL_EXPORT_LDFLAGS: Same as the LOCAL_EXPORT_CFLAGS but for the linker flags.
LOCAL_EXPORT_C_INCLUDES: This variable allows recording set include paths that will be added to the LOCAL_C_INCLUDES definition of any other module that is using this module through either LOCAL_STATIC_LIBRARIES or LOCAL_SHARED_
LIBRARIES.
LOCAL_SHORT_COMMANDS: This variable should be set to true for modules with a very high number of sources or dependent static or shared libraries. Operating systems like Windows only allow a maximum of 8191 characters on the
command line; this variable makes the build commands shorter than this limit by breaking them. This is not recommended for smaller modules since enabling it will make the build slower.
LOCAL_FILTER_ASM: This variable defines the application that will be used to filter the assembly files from the LOCAL_SRC_FILES.