(Transfer) Analysis of NDK Android Program Compilation Principle

Thanks for the summary of the original author, the address is as follows:

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. But you don't have to explicitly set the corresponding environment variables for these two variables. Because if NDK_ROOT is not defined, the string "build/core" is used in the script to match the full path of the current script, and the part in front of the string is NDK_ROOT. If NDK_PROJECT_PATH is defined, the script will look for application.mk and android.mk in the jni directory under this path; if NDK_PROJECT_PATH is not defined, the script will look for "jni/Android.mk" to match to get NDK_PROJECT_PATH, and then in the NDK_PROJECT_PATH directory Find application.mk and android.mk under. If APP_BUILD_SCRIPT in application.mk does not specify the path of Android.mk, find Android.mk in the directory where application.mk is currently located; otherwise, find Android.mk directly according to APP_BUILD_SCRIPT.

To compile the program under Android, in addition to Android.mk, Application.mk is also necessary. By looking at buid/core/build-local.mk, you can know that if you don't write Application.mk, it will use build/core/default-application.mk by default, and then call Android.mk to compile according to the APP_BUILD_SCRIPT in it. So , if you just don't need to specify the cpu architecture and other information in Application.mk, you can compile correctly without writing Application.mk.

APP_BUILD_SCRIPT in Application.mk is an optional variable, you can decide whether to set a specific value according to your needs. Because of this feature, we can divide Application.mk into two cases: $Project/jni/ and $NDK_ROOT/jni/.

If the environment variable NDK_PROJECT_PATH is not specified, the compiler will obtain NDK_PROJECT_PATH by matching jni/Android.mk in the directory where the compilation command is currently executed. Therefore, when executing, you can only execute $NDK_ROOT/ndk-build in the directory of the current application of $Project to compile.

Application.mk can be placed in your $Project/jni/ directory together 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 in the jni directory under make's current directory. mk. If the value of the APP_BUILD_SCRIPT variable is specified in Application.mk, the compiler will read Android.mk according to the value of this variable. So. Generally, when both Application.mk and Android.mk are in the $Project/jni/ directory, we do not need to specify APP_BUILD_SCRIPT in Application.mk, and let the compiler read Android.mk in the $Project/jni/ directory directly. That's it.

For the case where Application.mk is under $NDK_ROOT/jni/, you must specify APP_BUILD_SCRIPT, APP_PROJECT_PATH is also optional, and you must specify the environment variable NDK_PROJECT_PATH---the compiler finds $NDK_ROOT/jni/Application according to this environment variable. mk.

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

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326766829&siteId=291194637