问题描述
在Android NDK文档中,存在以下语句:
In the documentation for Android NDK, the following statement is present:
据此我可以解释为应该将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:
我从中收集到一个信息,即应该在我的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
- 在项目的jni/目录中创建一个Android.mk文件
- ...使用ndk-build编译您的本机代码
- Create an Android.mk file in the jni/ directory of your project
- ... 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
是必需的,而Application.mk
不是必需的. -
Android.mk
包含模块定义,并且Application.mk
描述体系结构,编译器选项和其他全局"选项. 根据设计, -
Android.mk
与Application.mk
正交.如果Android.mk
包含3个模块,并且Application.mk
2个ABI(例如arm和x86),则NDK将构建(3 * 2)个工件. -
Application.mk
中的变量出现在Android.mk
中,因此,例如,您可以使用Android.mk
中的APP_ABI
链接与体系结构相关的库. - 有些项目包含很多makefile,因此将它们保存在
Application.mk
中是一种干净的方法. - 但是
Application.mk
仍然只是设计决定,本来可以完成的.
Android.mk
is mandatory andApplication.mk
is not.Android.mk
contains module definitions andApplication.mk
describes architecture, compiler options, and other "global" options.Android.mk
is orthogonal toApplication.mk
by design. IfAndroid.mk
contains 3 modules, andApplication.mk
2 ABIs (e.g. arm and x86), then NDK will build (3 * 2) artifacts.- Variables from
Application.mk
appears inAndroid.mk
, so you can use, for instance,APP_ABI
inAndroid.mk
to link architecture dependent libraries. - There are complex projects with a lot of makefiles and keeping common options in
Application.mk
is a clean way. - But still
Application.mk
is just a design decision, it could've been done differently.
这篇关于Android.mk应该在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!