Where is Android.mk supposed to be?

前端 未结 2 2227
忘掉有多难
忘掉有多难 2021-02-20 02:13

In the documentation for Android NDK, the following statement is present:

The Android.mk file resides in a subdirectory of your project\'s jni/ directory

2条回答
  •  既然无缘
    2021-02-20 02:36

    Expected project structure

    /
     |
     +-- jni/
     |    |
     |    +-- Android.mk
     |    +-- [Application.mk] (optionally)
     |    +-- main.c
     |
     +-- AndroidManifest.xml
    

    According to a short guide from here: https://developer.android.com/ndk/guides/concepts

    1. Create an Android.mk file in the jni/ directory of your project
    2. ... compile your native code using the ndk-build
      $ cd //
      $ /ndk-build
      

    However, there is a way to define custom NDK project structures using ndk-build with arguments.

    Plain structure

    /
     |
     +-- Android.mk
     +-- [Application.mk]
     +-- main.c
    
    $ cd 
    $ ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=Android.mk
    

    Android.mk vs Application.mk

    why there is a need for multiple makefiles when Android.mk will contain the definitions for all modules anyway-that could just as well be placed in Application.mk.

    1. Android.mk is mandatory and Application.mk is not.
    2. Android.mk contains module definitions and Application.mk describes architecture, compiler options, and other "global" options.
    3. Android.mk is orthogonal to Application.mk by design. If Android.mk contains 3 modules, and Application.mk 2 ABIs (e.g. arm and x86), then NDK will build (3 * 2) artifacts.
    4. Variables from Application.mk appears in Android.mk, so you can use, for instance, APP_ABI in Android.mk to link architecture dependent libraries.
    5. There are complex projects with a lot of makefiles and keeping common options in Application.mk is a clean way.
    6. But still Application.mk is just a design decision, it could've been done differently.

提交回复
热议问题