JNI development in Android (2) Android. mk writing

Source: Internet
Author: User

Android. mk File Syntax:

 ---------- cut here ------------------   LOCAL_PATH := $(call my-dir)   include $(CLEAR_VARS)   LOCAL_MODULE    := hello-jni   LOCAL_SRC_FILES := hello-jni.c   include $(BUILD_SHARED_LIBRARY)---------- cut here ------------------

Now, let's explain the following lines: local_path: = $ (call my-DIR). The definition of the local_path variable must start with the Android. mk file. It is used to search for source files in the Development tree. In this example, the macro function "My-Dir" provides a build system for returning to the current directory (that is, the path included in this project Android. mk file itself ). $ (Clear_vars) by constructing a system and a special gnu makefile file with the clear_vars variable, many variables of local_xxx will be cleared for you (such as local_module, local_src_files, local_static_libraries, and so on .), In addition to local_path. This is necessary because all construction control files analyze all variables in a single GNU make execution context. Local_module: = HELLO-JNILOCAL_MODULE variables must be defined to determine each module, which you describe in your android. mk. The name must be * unique and contain no spaces. Note that the build system automatically adds the appropriate prefix and suffix of the generated file. In other words, a shared library module named 'foo' will generate 'libfoo. So ". Important: If you name your module libfoo, the build system will not add another 'lib' prefix and generate libfoo. So. This is to support the Android. mk file, originated from the Android platform. Local_src_files: = HELLO-jni.cLOCAL_SRC_FILES variables must contain list files for C and/or C ++ source files to be built and assembled into modules. It should be noted that you should not list the header files and contained files, because the generation system will automatically establish a link for you, only listing the source files will be passed directly to the compiler. Note that the default extension of the C ++ source file is ". cpp. However, you can specify a different local_cpp_extension by defining variables. Do not forget the original "." (that is, ". cxx" instead of "cxx "). $ (Build_shared_library) build_shared_library is a variable provided by the compilation system, that is, a GNU makefile script, which collects all the local_xxx variables defined in, because the latest information "include $ (clear_vars) and decide what to build and how to do it. There is also build_static_library to generate a static library. That is to say:
Include $ (build_shared_library) and include $ (build_static_library) Determine whether the current library is created in a shared or static manner.
You can define multiple libraries in an android. mk file. The structure is as follows:
include $(CLEAR_VARS)LOCAL_MODULE    := nativeLOCAL_SRC_FILES := native.cinclude $(BUILD_SHARED_LIBRARY)

In addition to local_module, other MK files can be introduced in the include mode during development for modularization.

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.