Android Jni ANDROID.MK often use statements

Source: Internet
Author: User

Just to involve JNI development involves android.mk writing, which is also a makefile language.

For example, the project provided in the above blog post!

<1>: Information printing: Since it's a simple language, you should first know the syntax part of the script information that you can print: One is the basic information type, one is the warning, the error type

$ (Info TEXT ...) when this function runs, it will output: Text ...

$ (Error TEXT ...) When this function is run, it outputs: text ... and terminates the run of make. $ (warning text ...) When this function is run, it will output: TEXT ..., but make will continue to run.


Simply add the above section to the ANDROID.MK to print the basic information in the Android.mk file.

Like what:

Local_path: = $ (call My-dir) $ (Warning $ (local_path))

When the build so library, the console prints out:

Jni/android.mk:2: JNI


<2>: ANDROID.MK tree structure from the top of the link: if most of the C library is in the jni/libmp3lame/folder, then generally in the Libmp3lame sub-folder is also best to write a android.mk file, In fact, the JNI of Android follows the Linux file tree management method, for example, I create a new android.mk file under the Libmp3lame folder above:

Local_path: = $ (call My-dir) include $ (clear_vars) Local_module: = lamejnilocal_src_files: = bitstream.c encoder.c fft.c ga IN_ANALYSIS.C id3tag.c lame.c mpglib_interface.c newmdct.clocal_src_files + = presets.c psymodel.c quantize_pvt.c quantize.c reservoir.c set_get.c tables.c util.clocal_src_files + = takehiro.c vbrquantize.c VbrTag.c Version.cLOCAL_SRC _files + = Xmm_quantize_sub.clocal_ldlibs: =-lloginclude $ (build_shared_library)

Then change the android.mk in the Jni root folder to:

Local_path: = $ (call My-dir) $ (Warning $ (local_path)) Durian_makefile_dir: =./libmp3lamelocal_src_files: = durianlame.c Durianutils.cinclude $ (Local_path)/./$ (durian_makefile_dir)/android.mk

It is possible to include the required MK file through the compiler's include, where Local_path gets, and the other is the path:

Include $ (local_path)/./$ (durian_makefile_dir)/android.mk

Add a print record:

$ (Warning $ (durian_makefile_dir)/android.mk)

Output:

Jni/android.mk:8:./libmp3lame/android.mk


Here's a general notation: search for the android.mk file under all subfolders by the given subfolder path:

Include $ (foreach m,$ (Durian_makefile_dir), $ (local_path)/./$m/android.mk) #include $ (local_path)/./$ (durian_ Makefile_dir)/android.mk

Stare down the front way.

Of course there is a second solo of all trees below the writing, personally not recommended:

Include $ (call All-subdir-makefiles)


<3>: All related C or CPP files: The same is done by traversing the specified subfolder: or immediately following the ANDROID.MK content:

Durian_c_srcs_dir: =$ (local_path) Durian_all_c_srcs: = $ (foreach m,$ (Durian_c_srcs_dir), $ (wildcard $m/*.c)) $ (Info $ ( DURIAN_ALL_C_SRCS)) Local_src_files: = $ (Durian_all_c_srcs) #durianlame. C DURIANUTILS.C

Above is in the Local_path folder, which is the folder in the root folder is JNI and folders, but probably very many sub-folders under Android.mk Also, this time Local_path path is to point to subfolders,<1> Also the debug information given in the display is also the JNI folder. After wildcard in this folder, return all the C file list information under this folder,

Wildcard How to use:

$ (wildcard PATTERN ...) It is expanded to a list of all files that already exist, separated by spaces, that match this pattern. Assume that there are no files that conform to this pattern. The function ignores the pattern character and returns NULL.


Note Its return value, which returns a list of information.

The following changes it to the Android.mk file under Libmp3lame:

Local_path: = $ (call My-dir) $ (Info $ (local_path)) include $ (clear_vars) Local_module: = Lamejnilocal_src_files: = BITSTREAM.C encoder.c fft.c gain_analysis.c id3tag.c lame.c mpglib_interface.c newmdct.clocal_src_files + = PRESETS.C PSYMODEL.C quantize_pvt.c quantize.c reservoir.c set_get.c tables.c util.clocal_src_files + = takehiro.c vbrquantize.c VBRTAG.C Version.clocal_src_files + = xmm_quantize_sub.c$ (Info $ (local_src_files)) Local_ldlibs: =-lloginclude $ (BUILD _shared_library)


c file very much, when you join must be very troublesome.

Ability to change such as the following:

Durian_c_srcs_dir: =$ (local_path) Durian_all_c_srcs: = $ (foreach m,$ (Durian_c_srcs_dir), $ (wildcard $m/*.c)) Durian_ All_c_srcs: = $ (subst $ (local_path)/,,$ (Durian_all_c_srcs)) Local_src_files: = $ (DURIAN_ALL_C_SRCS)

Please note:

Durian_all_c_srcs: = $ (subst $ (local_path)/,,$ (DURIAN_ALL_C_SRCS))

Subst is the subfolder of the list that gets the previous Durian_all_c_srcs libmp3lame all the names are removed, the reader can stare out of the line and look at the printed log information. Of course it can be used under the JNI root folder, which is more generic.

Sometimes it is necessary to use other so, assuming that they only provide so and so the corresponding header file, then so put to Libs below, the header file by putting into a separate folder, the same through the above way to import the header file.


<4>: Local_cflags How to use: This tag is completely for the compiler, the macro definition of the disguised wording.

At some point, compile the source code need to define macro variables, this time, we can directly in the corresponding source code to change, but there are some cases, we are unable to define the macro variables in other people's source code, this time, it is necessary to use the local_cflags, the proportion of the following: Java code local_cflags  + =-d__favor_bsd  This line of code is based on the original CFLAGS, and then define a macro variable __favor_bsd  similar to the # define __favor_ Bsd
Local_cflags: Optional compiler option. Used when compiling C-code files.

This may be useful to specify an additional include path (relative to the NDK's top-level folder), a macro definition, or a compilation option. Note: Do not change the optimization/debugging level in android.mk. Just specify the appropriate information in the APPLICATION.MK. will take the initiative to deal with this problem for you, during commissioning, will let the NDK to actively generate practical data files

Let's just give a practical example:

In the Android.mk file join:

Local_cflags + =-ddurian_define   //defines the macro, which can be inferred from the code

Equivalent to a macro that defines a durian_define.

The following detailed use method: in your program through the following inference whether to call the function getdurianinformation.

#ifdef durian_define       getdurianinformation (); #endif


Because the above is the most online asked, so special to come, the rest of the references to my Cnblog blog:

Http://www.cnblogs.com/MMLoveMeMM/articles/3909809.html


<5>: Writing android.mk may require a lot, but the actual functions often used can be attributed to the following:

1, Wildcard: Extended wildcard 2, Notdir: Remove Path 3, PATSUBST: replace wildcard characters
Another function subst the character typeface minus

Of course, different companies and project may have many others.







































Android Jni ANDROID.MK often use statements

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.