Android NDK:如何将 Android.mk 包含到另一个 Android.mk(分层项目结构)中? [英] Android NDK: how to include Android.mk into another Android.mk (hierarchical project structure)?

查看:17
本文介绍了Android NDK:如何将 Android.mk 包含到另一个 Android.mk(分层项目结构)中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看起来有可能,但我的脚本产生了奇怪的结果:

Looks like it's possible, but my script produces odd results:

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

include $(LOCAL_PATH)/libos/Android.mk
include $(LOCAL_PATH)/libbase/Android.mk
include $(LOCAL_PATH)/utils/Android.mk

LOCAL_MODULE := native
include $(BUILD_SHARED_LIBRARY)

只有第一个包含被解析得很好,其他 Android.mk 文件被搜索到奇怪的路径.有什么建议吗?

Only the first include is being parsed fine, other Android.mk files are being seacrhed at odd paths. Suggestions?

更新:我破坏了我的建筑环境...在办公室还可以,但在家里 LOCAL_PATH:= $(call my-dir) 将 LOCAL_PATH 定义为 NDK 目录而不是项目目录.这是我的建筑批次:

Update: I have broken my building environment... It was OK in the office, but at home LOCAL_PATH:= $(call my-dir) defines LOCAL_PATH to NDK dir instead of project dir. This is my batch for building:

set BASHPATH=K:cygwininash
set PROJECTDIR=/cygdrive/h/Alex/Alex/Work/Android/remote-android
set NDKDIR=/cygdrive/h/Alex/Programming_Docs/Android/android-ndk-r6/ndk-build
set APP_BUILD_SCRIPT=/cygdrive/h/Alex/Alex/Work/Android/project/jni/Android.mk
set DEV_ROOT=h:/Alex/Alex/Work/Android/project

%BASHPATH% --login -c "cd %PROJECTDIR% && %NDKDIR%"

更新:我完全不明白这东西是如何组成路径的.我在/cygdrive/d/project/jni//cygdrive/d/Soft/project/jni/libos/src/libos.cpp"之类的路径中遇到错误.这是在我决定在根目录中指定所有文件之后Android.mk 而不是包含子模块.

Update: I absolutely don't understand how does this thing compose paths. I'm getting errors with paths like "/cygdrive/d/project/jni//cygdrive/d/Soft/project/jni/libos/src/libos.cpp'. This is after I decided to specify all files in the root Android.mk instead of including submodules.

更新 2:不走运,这也不起作用:

Update 2: No luck, this doesn't work either:

LOCAL_PATH:= $(call my-dir)
# Include makefiles here.
include $(LOCAL_PATH)/libos/Android.mk
include $(LOCAL_PATH)/libbase/Android.mk
include $(LOCAL_PATH)/utils/Android.mk

# Clear variables here.
 include $(CLEAR_VARS)

推荐答案

这里已经很晚了,但万一有人读到这个问题,一种解决路径损坏问题的方法(指向从jni) 是在你的 jni 文件夹中:

Pretty late here, but in case somebody reads this question, one way to get past the problem of broken paths(pointing to the ndk insted of your files from the jni) is to have in your jni folder:

include $(call all-subdir-makefiles)

然后在它的每个子文件夹中(在 OP 的情况下为 libos、libbase 和 ustils)一个这种形式的 Android.mk:

and then in every subfolder of it (libos, libbase and ustils inthe case of OP) an Android.mk of this form:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES        := $(LOCAL_PATH)
LOCAL_MODULE            := utils
LOCAL_SRC_FILES         := one.c
LOCAL_SRC_FILES         += two.c

第二个 Android.mk 与 jni 文件夹中的子文件夹中的 one.c 和 two.c 文件.

where this second Android.mk in with the one.c and two.c files in a subfolder found in the jni folder.

请注意,尝试一些事情

LOCAL_PATH_BIS_WEIRD_OTHER_NAME := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES        := $(LOCAL_PATH_OTHER_FUNKY_NAME)
LOCAL_MODULE            := utils
LOCAL_SRC_FILES         := one.c
LOCAL_SRC_FILES         += two.c

将再次导致编译器在寻找 ndk 所在的源代码时感到困惑.

will lead again to a confused compiler looking for your source code where the ndk is.

因此,在 jni 的每个子目录中完全以这种形式使用 LOCAL_PATH := $(call my-dir)include $(call all-subdir-makefiles)strong> 在 jni 本身中,你不应该有问题.

So, use the LOCAL_PATH := $(call my-dir) EXACTLY in this form in every subdirectory of the jni and include $(call all-subdir-makefiles) in the jni itself and you shouldn't have problems.

希望这会对某人有所帮助.

Hope this will help someone.

发生这种行为是因为包含 $(CLEAR_VARS) 没有删除保存在 LOCAL_PATH 中的内容.

this behaviour happens because what is kept in LOCAL_PATH is not deleted by include $(CLEAR_VARS).

这篇关于Android NDK:如何将 Android.mk 包含到另一个 Android.mk(分层项目结构)中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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