Android.mk应该在哪里? [英] Where is Android.mk supposed to be?

查看:959
本文介绍了Android.mk应该在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android NDK文档中,存在以下语句:

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

Android.mk文件位于项目的jni/目录的子目录中[...] http://developer.android.com/ndk/guides/android_mk.html

The Android.mk file resides in a subdirectory of your project's jni/ directory [...] http://developer.android.com/ndk/guides/android_mk.html

据此我可以解释为应该将Android.mk文件放置在[project_path]/jni/[module_name]/Android.mk中,每个模块都有其自己的特定Android.mk文件,因为这是它与应用程序范围的Application.mk文件不同的地方,但是当我执行ndk-build,我收到以下错误消息:

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:./jni下没有Android.mk
Android NDK:如果这是有意的,请定义APP_BUILD_SCRIPT来指向
Android NDK:到有效的NDK构建脚本.

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.

我从中收集到一个信息,即应该在我的Application.mk文件旁边创建一个Android.mk文件,或者在Application.mk中定义APP_BUILD_SCRIPT指向一个单独的Android.mk文件.这与文档相矛盾,并且让我想知道为什么当Android.mk仍然包含所有模块的定义时,为什么需要多个makefile-也可以放在Application.mk中.

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.

通过阅读几个NDK示例项目,我发现确实Android.mk文件与Application.mk位于同一目录中,并且在它们上执行ndk-build似乎可行.

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.

缺少什么?

推荐答案

预期的项目结构

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

根据此处的简短指南: https://developer.android.com/ndk/guides/concepts

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

  1. 在项目的jni/目录中创建一个Android.mk文件
  2. ...使用ndk-build编译您的本机代码
  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

但是,有一种方法可以使用带有参数的ndk-build来定义自定义NDK项目结构.

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

<mylib>/
 |
 +-- Android.mk
 +-- [Application.mk]
 +-- main.c

$ cd <mylib>
$ ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=Android.mk

Android.mk与Application.mk

当Android.mk无论如何都包含所有模块的定义时,为什么需要多个makefile-也可以将它们放置在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是必需的,而Application.mk不是必需的.
  2. Android.mk包含模块定义,并且Application.mk描述体系结构,编译器选项和其他全局"选项.
  3. 根据设计,
  4. Android.mkApplication.mk正交.如果Android.mk包含3个模块,并且Application.mk 2个ABI(例如arm和x86),则NDK将构建(3 * 2)个工件.
  5. Application.mk中的变量出现在Android.mk中,因此,例如,您可以使用Android.mk中的APP_ABI链接与体系结构相关的库.
  6. 有些项目包含很多makefile,因此将它们保存在Application.mk中是一种干净的方法.
  7. 但是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.

这篇关于Android.mk应该在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆