Android NDK How-To ---- Android 4.4

简介: Android NDK How-To: =================== A collection of tips and tricks for NDK users How to force the display of build command...
Android NDK How-To:
===================

A collection of tips and tricks for NDK users


How to force the display of build commands:
-------------------------------------------

Do "ndk-build V=1" and actual build commands will be
displayed. This can be used to verify that things are compiled
as you expect them to, and check for bugs in the NDK build system.

(The V=1 trick comes from the Linux kernel build system)


How to force a rebuild of all your sources:
-------------------------------------------

Use GNU Make's "-B" option, as in:

      ndk-build -B


How to store your native sources in a location other than $PROJECT/jni:
-----------------------------------------------------------------------

First, you can simply tell your $PROJECT/jni/Android.mk to include
another Android.mk that are located in different places.

Alternatively, you can define APP_BUILD_SCRIPT in your Application.mk
to point to an alternative Android.mk file.


How to build a project's native files without cd-ing to it:
-----------------------------------------------------------

Sometimes, you may need to rebuild a project's native file without
being able to cd to its top-level path from the command-line. This
is do-able by using the GNU-Make '-C <path>' option, as in:

        ndk-build -C <project-path>


How to store your Application.mk in a location other than $PROJECT/jni:
-----------------------------------------------------------------------

Starting with NDK r4, you can simply place the file under $PROJECT/jni/
and launch the 'ndk-build' script from your project tree.

If you want to use 'ndk-build' but place the file to a different location,
use a GNU Make variable override as:

        ndk-build NDK_APPLICATION_MK=/path/to/your/Application.mk

If you're using the legacy $NDK/apps/<name> build method, you can create
a symbolic link to your final Application.mk there. For example, imagine
that you wrote:

        $PROJECT/foo/Application.mk

You can create a symlink like with a command like:

        ln -s $PROJECT/foo  $NDK/apps/<name>

This will make $NDK/apps/<name>/Application.mk point directly to
$PROJECT/jni/Application.mk

Note that generated files will still go under $NDK/out/apps/<name> though.

Windows users: The NDK is only supported on Cygwin, which implements
symbolic links through the "ln -s" command, as in:

        ln -s  <target>  <link>


How to properly add include directories to your module declaration:
-------------------------------------------------------------------

If you define several modules, it is common to need to include one
module's header while compiling another one. For example, consider
the following example:

        $PROJECT/jni/foo/
          Android.mk
          foo.h
          foo.c

        $PROJECT/jni/bar/
          Android.mk
          bar.c

Where the 'bar.c' uses '#include <foo.h>'. You will need to add the
path to the 'foo' module in jni/bar/Android.mk to build it properly.

One is tempted to use the following:

        LOCAL_C_INCLUDES := ../foo

However this will not work because all compilation happens from the
directory where 'ndk-build' is invoked, and include files must be
relative to it.

The correct line is instead:

        LOCAL_C_INCLUDES := $(LOCAL_PATH)/../foo

Which uses a path relative to $(LOCAL_PATH), in the case where you would
need to move 'foo' and 'bar' to a deeper level in the 'sources' hierarchy.

In case you absolutely need it, you can also use NDK_APP_PROJECT_PATH to
point to your project directory:

        LOCAL_C_INCLUDES := $(NDK_APP_PROJECT_PATH)/jni/foo

However, we don't recommend using this, paths relative to $(LOCAL_PATH)
being better.
目录
相关文章
|
数据采集 编解码 Ubuntu
Android流媒体开发之路二:NDK C++开发Android端RTMP直播推流程序
Android流媒体开发之路二:NDK C++开发Android端RTMP直播推流程序
278 0
|
1月前
|
编译器 Android开发
配置环境变量,使CMakeLists.txt可直接使用Android NDK工具链编译项目
配置环境变量,使CMakeLists.txt可直接使用Android NDK工具链编译项目
|
2月前
|
Java Android开发 C++
🚀Android NDK开发实战!Java与C++混合编程,打造极致性能体验!📊
在Android应用开发中,追求卓越性能是不变的主题。本文介绍如何利用Android NDK(Native Development Kit)结合Java与C++进行混合编程,提升应用性能。从环境搭建到JNI接口设计,再到实战示例,全面展示NDK的优势与应用技巧,助你打造高性能应用。通过具体案例,如计算斐波那契数列,详细讲解Java与C++的协作流程,帮助开发者掌握NDK开发精髓,实现高效计算与硬件交互。
138 1
|
3月前
|
开发工具 Android开发
解决Android运行出现NDK at /Library/Android/sdk/ndk-bundle did not have a source.properties file
解决Android运行出现NDK at /Library/Android/sdk/ndk-bundle did not have a source.properties file
169 4
解决Android运行出现NDK at /Library/Android/sdk/ndk-bundle did not have a source.properties file
|
3月前
|
开发工具 Android开发
解决Android Studio编译提示NDK is missing a “platforms“ directory
解决Android Studio编译提示NDK is missing a “platforms“ directory
208 1
|
4月前
|
Java Android开发 C++
🚀Android NDK开发实战!Java与C++混合编程,打造极致性能体验!📊
【7月更文挑战第28天】在 Android 开发中, NDK 让 Java 与 C++ 混合编程成为可能, 从而提升应用性能。**为何选 NDK?** C++ 在执行效率与内存管理上优于 Java, 特别适合高性能需求场景。**环境搭建** 需 Android Studio 和 NDK, 工具如 CMake。**JNI** 构建 Java-C++ 交互, 通过声明 `native` 方法并在 C++ 中实现。**实战** 示例: 使用 C++ 计算斐波那契数列以提高效率。**总结** 混合编程增强性能, 但增加复杂性, 使用前需谨慎评估。
141 4
|
5月前
|
XML Java Android开发
Android Studio2.2 中支持NDK开发HelloJNI例子
Android Studio2.2 中支持NDK开发HelloJNI例子
34 0
|
6月前
|
Java 开发工具 Android开发
鸿蒙HarmonyOS 与 Android 的NDK有什么区别?
鸿蒙(HarmonyOS)和Android的NDK(Native Development Kit)是两个不同的概念,它们在设计理念、架构、开发方式和目标平台等方面存在着一些显著的不同。
333 0
|
6月前
|
传感器 Java 开发工具
[NDK/JNI系列03] Android Studio集成NDK开发环境
[NDK/JNI系列03] Android Studio集成NDK开发环境
69 0
|
6月前
|
Java Android开发 C++
安卓SO层开发 -- 第一个NDK项目
安卓SO层开发 -- 第一个NDK项目
39 0
下一篇
无影云桌面