Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is Android.mk supposed to be?

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 [...] http://developer.android.com/ndk/guides/android_mk.html

I can interpret from this that an Android.mk file should be placed in [project_path]/jni/[module_name]/Android.mk, each module having its own specific Android.mk file since this is what differentiates it from the application wide Application.mk file, but when I execute ndk-build I get the following error message:

Android NDK: There is no Android.mk under ./jni
Android NDK: If this is intentional please define APP_BUILD_SCRIPT to point
Android NDK: to a valid NDK build script.

I gather from that I am supposed to create a single Android.mk file alongside my Application.mk file or define APP_BUILD_SCRIPT in Application.mk to point to a single Android.mk file. This contradicts the documentation and leaves me wondering 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.

Reading a couple of NDK sample projects I found out that, indeed, the Android.mk file is in the same directory as Application.mk and executing ndk-build on them seems to work.

What is missing?

like image 763
Max Ocd Avatar asked Dec 19 '15 15:12

Max Ocd


People also ask

What is Local_cflags?

LOCAL_CFLAGS is applied to the current module, and is undefined after an include $(CLEAR_VARS) . APP_CFLAGS is applied to all modules.

What is Ndk_project_path?

NDK_PROJECT_PATH - the location of your project NDK_APPLICATION_MK - the path of the Application.mk file APP_BUILD_SCRIPT - the path to the Android.mk file. These are needed to override the default values of the build script, which expects things to be in the jni folder.

What is a .MK file?

Makefile used by software compilers and linkers for building program executable from source files; may be a full Makefile or may contain additional rules referenced by a Makefile.

What is CMake used for in Android?

The Android NDK supports using CMake to compile C and C++ code for your application.


1 Answers

Expected project structure

<project>/
 |
 +-- 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 <path>/<to>/<project>
    $ <ndk>/ndk-build
    

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

Plain structure

<mylib>/
 |
 +-- Android.mk
 +-- [Application.mk]
 +-- main.c
$ cd <mylib>
$ 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.
like image 52
Alexander Fadeev Avatar answered Oct 05 '22 18:10

Alexander Fadeev