• 【翻译】(4)How To


    -----------------

    英文文档见android-ndk-r5b的documentation.html

    属于Android Native Development Kit (NDK)的一部分

    见http://developer.android.com/sdk/ndk/(需要代理)

    翻译仅个人见解

    -----------------

    Android NDK How-To:

    Android NDK指南:

    ===================

    A collection of tips and tricks for NDK users

    一些给NDK用户的提示和技巧

    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.

    执行“ndk-build V=1”则实际构建命令将会被显示。可用于验证那些东西正如你所预期的那样被编译,以及检查NDK构建系统的缺陷。

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

    (V=1的技巧来自Linux内核构建系统)

    How to force a rebuild of all your sources:

    如何强制你的所有代码的重新构建:

    -------------------------------------------

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

    使用GNU Make的-B选项,如下所示:

       ndk-build -B

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

    如何让你的原生源代码放在不同于$PROJECT/jni的地方(注:jni是放置jni的C文件的约定目录)

    -----------------------------------------------------------------------

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

    首先,你可以简单地让你的$PROJECT/jni/Android.mk包含位于不同位置的另一个Android.mk。(注:也就是说$PROJECT/jni/Android.mk必须存在)

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

    另一种方法是,你可以在Application.mk中定义APP_BUILD_SCRIPT的值指向一个可选的Android.mk的文件。

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

    如何不使用cd命令来构建一个工程的原生文件

    -----------------------------------------------------------

    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:

    有时,你可能需要重新编译一个工程的原生文件但不能在命令行上用cd命令切换到它的顶级路径。可以使用GNU-Make的-C <路径>选项,如下所示:

        ndk-build -C <project-path>

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

    如何保存你的Application.mk在不同于$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.

    从NDK r4开始,你可以简单地放置文件在$PROJECT/jni/目录下并且在你的工程树上运行ndk-build脚本。

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

    如果你想使用ndk-build但放置文件到一个不同的位置,使用一个GNU MAKE变量重载为:

        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:

    如果你使用旧有的$NDK/apps/<名称>构建方法,你可以创建一个符号链接到你的最终Application.mk那里。例如,假设你这样写:

      $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

    这将使$NDK/apps/<名称>/Application.mk直接指向$PROJECT/jni/Application.mk

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

    不过注意,生成的文件将仍旧跑到$NDK/out/apps/<名称>。(注:out目录而非apps目录)

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

    Windows用户:NDK只在Cygwin上被支持,实现符号链接是通过ln -s命令,如下所示:

        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

    (注:上面是说foo和bar目录下有哪些文件)

    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.

    这里bar.c使用#include <foo.h>语句。你将需要在jni/bar/Android.mk中添加路径到foo模块以正确地构建它。(注:在C中,#include <...>是用于包含.h头文件。.h头文件仅用于预编译,生成.o文件实际上只需要.c文件。由于C的模块编译是分布式的,需要借助#include来事先声明模块外的函数。头文件的目录可以在编译命令行中用选项来指定)

    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.

    然而,这将不能工作,因为所有编译发生在执行ndk-build的地方,而包含文件必然相对于这个地方。(注:前面提到,有可能不是在Android.mk的目录执行ndk-build)

    The correct line is instead:

    正确的命令行应该是:(注:在Android的工程文件中经常用$(LOCAL_PATH)取得Android.mk所在目录)

      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.

    它使用相对于$(LOCAL_PATH)的路径,通常用在你需要把foo和bar移动到源代码树的更深层次的情况下。(注:实际上在Cygwin下可以用/cygdrive/<盘符>/...指定绝对路径也可,不过有点麻烦而已)

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

    一旦你一定需要这样,你还可以使用NDK_APP_PROJECT_PATH指向你的工程目录:

      LOCAL_C_INCLUDES := $(NDK_APP_PROJECT_PATH)/jni/foo

    However, we don't recommend using this, paths relative to $(LOCAL_PATH) being better.

     然而,我们不建议使用这种方法,使用相对于$(LOCAL_PATH)的路径较好。

  • 相关阅读:
    解构赋值用在函数参数默认值中的一些情况
    obaa源码加注
    omi-mp-create源码加注
    小程序表情选择器
    小程序QQ版表情解析组件
    用TamperMonkey去掉cdsn中的广告
    小程序自定义tabbar
    Python基础入门——安装与运行
    LaTeX安装与入门
    Java 运行环境安装
  • 原文地址:https://www.cnblogs.com/qq78292959/p/2232945.html
Copyright © 2020-2023  润新知