An analysis of the compiling principle of Android Program (NDK compilation)

Source: Internet
Author: User

Original link http://blog.csdn.net/nodeathphoenix/article/details/7684230

The variables ndk_root and Ndk_project_path are used in the compilation script under Android Build/core. However, neither of these variables you have to explicitly set the corresponding environment variable. Because if Ndk_root is not defined, the script takes the string "Build/core" to match the full path of the current script, and the portion that precedes the string is ndk_root. If Ndk_project_path is defined, the script goes down the path to find Application.mk and android.mk under the JNI directory, and if no ndk_project_path is defined, the script looks for "jni/android.mk "To match to get Ndk_project_path, then find Application.mk and Android.mk in the Ndk_project_path directory. If app_build_script in application.mk does not specify a path for android.mk, find android.mk in the current directory where application.mk is located, otherwise, directly according to App_build_ Script to find ANDROID.MK.

Android under the compiler program, in addition to Android.mk, APPLICATION.MK is also necessary. By looking at Buid/core/build-local.mk it is known that if you do not write application.mk, it will use BUILD/CORE/DEFAULT-APPLICATION.MK by default, and then according to the App_build _script calls Android.mk to compile. So if you don't have to specify the CPU's architecture in APPLICATION.MK, you can compile it correctly without writing application.mk.

The App_build_script in application.mk is an optional variable that can be used to determine whether a specific value is set. Because of this feature, we can be divided into $project/jni/and $NDK according to the position of the application.mk _root/jni/in two cases.

If no environment variable Ndk_project_path is specified, the compiler obtains ndk_project_path in the directory under which the compiled command is currently executed, by matching jni/android.mk. Therefore, the execution can only be compiled by executing $ndk_root/ndk-build in the directory of the $project current application.

Application.mk can be placed in your $project/jni/directory with ANDROID.MK, if the value of the App_build_script variable is not specified in Application.mk, The compiler will automatically look for android.mk in the JNI directory under make's current directory. If the value of the App_build_script variable is specified in Application.mk, the compiler reads ANDROID.MK according to the value of the variable. So. Generally for application.mk and android.mk in the $project/jni/directory, we do not need to specify App_build_script in the APPLICATION.MK, directly let the compiler read $project/ The android.mk in the jni/directory is available.

For application.mk under $ndk_root/jni/, you must specify App_build_script,app_project_path is optional, and you must specify an environment variable ndk_project_ PATH---The compiler to find $ndk_root/jni/application.mk based on this environment variable.

Note App_project_path is optional for the "$PROJECT/jni/application.mk" file, but is mandatory for "$NDK/apps/<myapp>/application.mk".

An analysis of the compiling principle of Android Program (NDK compilation)

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.