如何写NDK静态库/调试Android.mk?静态、如何写、mk、NDK

2023-09-06 09:17:05 作者:梦里梦到醒不来的梦

我试图建立一个使用最新的Andr​​oid NDK(R5)静态库,我没有任何运气。我已经能够构建和运行样品(例如,HelloJni)没有任何问题,而且开始从'从零开始'的新项目却得到了不同的故事。

I'm trying to build a static library using the latest Android NDK (r5) and I'm not having any luck. I've been able to build and run the samples (for example, HelloJni) without any issues but starting a new project from 'scratch' has been a different story.

在这个实验中,我试图建立的libpng。我的文件夹结构如下所示:

For this experiment, I'm trying to build libpng. My folder structure looks like this:

root
|
+--- jni
      |
      +---- Android.mk ( one line: "include $(call all-subdir-makefiles)" )
      |
      +---- png
             |
             +---- Android.mk ( see below )
             |
             +---- { a bunch of .c and .h files )

所以,我有两个Android.mks。一个用于构建所有子项目,一个是libpng的子项目。根/ JNI / PNG / Android.mk看起来是这样的:

So I have two Android.mks. One for building all subprojects and one for the libpng subproject. root/jni/png/Android.mk looks like this:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := png
MODULE_PATH := $LOCAL_PATH
LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.c)
LOCAL_C_INCLUDES := $(wildcard $(LOCAL_PATH)/*.h)

LOCAL_INTERMEDIATE_TARGETS += junk
junk:
    echo $(LOCAL_SRC_FILES)

include $(BUILD_STATIC_LIBRARY)

该版本的设置似乎什么也不做(即从根文件夹运行NDK建造什么也不做,即使经过NDK,打造干净)。一个松散的运行(NDK建造V = 1),显示了一些RM -f调用(删除不存在的文件夹),但没有相关的项目或子项目。

This build setup seems to do nothing (ie running ndk-build from the root folder does nothing, even after an ndk-build clean). A verbose run (ndk-build V=1) shows some rm -f calls (deleting non-existent folders) but nothing related to the project or subproject.

我是pretty的兴趣为什么这个构建脚本失败,但这个过程应该是微不足道的,所以我敢肯定它没有非常有趣。我更感兴趣的是如何我可以开始进攻建立在我自己的错误。在脚本中的回声通话以上从不打 - 我不知道如何确定哪些值是为什么它会跳过子项目。有没有人找到了一种方法来了解构建系统是什么的尝试的怎么办?

I'm pretty interested in why this build script is failing but the process should have been trivial so I'm sure its nothing terribly interesting. I'm far more interested in how I could start to attack build bugs on my own. The echo call in the script above is never hit -- I have no idea how to determine what values are or why it skips the subproject. Has anyone found a way to know what the build system is trying to do?

我也希望有兴趣知道,如果有文档,这些工具或如果只是极少数的文本文件在NDK的文档文件夹?我一直在试图通过复制随机Android.mk的我发现从谷歌上搜索周围,但只有简单的NDK样本中使用的几个命令似乎证明件解决这个问题,所以经验实际上只是提出了新的问题。

I'd also be interested in knowing if there are docs for these tools or if its just the handful of text files in the NDK's docs folder? I've been trying to resolve this by copying pieces of random Android.mk's I've found from googling around but only the few commands used in the simple NDK samples appear to be documented, so the experience has actually just raised new questions.

推荐答案

我建议你摆脱module_path中的,而不是试图使用通配符:我还没有真正看到,工作的权利

I'd recommend getting rid of MODULE_PATH and not trying to use the wildcard: I haven't really seen that work right.

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := png
LOCAL_SRC_FILES := pngget.c pngread.c pngrutil.c pngtrans.c pngwtran.c png.c pngmem.c pngrio.c pngset.c pngwio.c pngwutil.c pngerror.c pngpread.c pngrtran.c pngwrite.c
LOCAL_C_INCLUDES := png.h pngconf.h pngpriv.h

include $(BUILD_STATIC_LIBRARY)

此外,还有一些严重的路径魔法我还没有完全破译:不知何故Eclipse中做正确的事情,但得到它通过适当的箍在命令行中跳还是漫无我

Also, there's some serious path magic I haven't fully deciphered: somehow Eclipse does the right thing, but getting it to jump through the proper hoops from the command line is still hit or miss for me.

编辑:所以在搞清楚了这一点,因为它已经有一段时间,因为我打了NDK的适度兴趣。当我用的是原来的文件并没有编译,但是当我把PNG源$ C ​​$ C在目录 JNI ,然后使用这个Android.mk文件:

so was moderately interested in figuring this out, as its been a while since I played with the NDK. When I use the original file it didn't compile, but when I placed the png source code in the directory jni and then use this Android.mk file:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := png
LOCAL_SRC_FILES := pngget.c pngread.c pngrutil.c pngtrans.c pngwtran.c png.c pngmem.c pngrio.c pngset.c pngwio.c pngwutil.c pngerror.c pngpread.c pngrtran.c pngwrite.c
LOCAL_C_INCLUDES := png.h pngconf.h pngpriv.h

include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := png2
LOCAL_STATIC_LIBRARIES := png

include $(BUILD_SHARED_LIBRARY)

它内置了两个libpng.a和libpng2.so在OBJ /本地/ armeabi文件夹。我猜它根本不会建立一个静态库,如果没有相关性。

it built both the libpng.a and libpng2.so in the obj/local/armeabi folder. I'm guessing it simply won't build an static library if there is no dependency.