在 Android NDK 中预编译静态库 - 源位于单独的目录树中
我正在尝试使用 Android NDK 预编译静态库。这个预编译的静态库稍后将与其他项目中的 JNI 代码链接。我没有与该库关联的 Eclipse 项目,因此我在该库的项目根目录中设置了一个框架 Android JNI 目录结构。
目录结构如下:
<root>/
Android/
jni/
Android.mk
Application.mk
iOS/
<other stuff here>
src/
<a bunch of *.c and *.h files here>
这是 Application.mk
文件:
APP_PLATFORM := android-8
APP_ABI := armeabi-v7a
这是 Android.mk
文件:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := imajilib
LOCAL_CFLAGS := -DANDROID_NDK
MY_FILES := $(wildcard $(LOCAL_PATH)/../../src/*.c)
LOCAL_SRC_FILES := $(MY_FILES:$(LOCAL_PATH)/%=%)
LOCAL_LDLIBS := -lGLESv2 -llog
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := ignore_this_imajilib
LOCAL_STATIC_LIBRARIES := imajilib
include $(BUILD_SHARED_LIBRARY)
ignore_this_imajilib
共享库模块是我学到的一个依赖技巧来自此处。
我通过 cd'ing 到 jni/ 目录并运行以下命令来编译该库:
~/path/to/ndk-build NDK_PROJECT_PATH=/path/to/<root> -B V=1
编译成功,没有任何问题。现在,我在 jni/
目录下有了新目录 libs/
和 obj/
。
libs/ 目录的结构是:
libs/
armeabi-v7a/
libignore_this_imajilib.so
这没问题,但理想情况下我也希望在这里看到 libimajilib.a
。
obj/
目录的结构为:
obj/
local/
armeabi-v7a/
libignore_this_imajilib.so
libimajilib.a
objs/
imajilib/
<this directory is empty>
src/
<a bunch of *.o and *.o.d files>
问题在于 *.o
和 *.od
文件的位置。我怀疑构建过程将它们放在那里,因为我在 Android.mk
文件中有 ../../src/*.c
,所以它要去 obj/local/armeabi-v7a/objs/imajilib/../../src 而我想看到它们obj/local/armeabi-v7a/objs/imajilib
。除了将源文件从 src/
复制并粘贴到 jni/
目录中之外,我没有其他办法解决这个问题,但我不想这样做code>src/ 目录在多个平台之间共享。
I am trying to precompile a static library using the Android NDK. This precompiled static library will later be linked with JNI code in other projects. I do not have an Eclipse project associated with the library so I set up a skeleton Android JNI directory structure within the library's project root directory.
The directory structure is as follows:
<root>/
Android/
jni/
Android.mk
Application.mk
iOS/
<other stuff here>
src/
<a bunch of *.c and *.h files here>
This is the Application.mk
file:
APP_PLATFORM := android-8
APP_ABI := armeabi-v7a
And this is the Android.mk
file:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := imajilib
LOCAL_CFLAGS := -DANDROID_NDK
MY_FILES := $(wildcard $(LOCAL_PATH)/../../src/*.c)
LOCAL_SRC_FILES := $(MY_FILES:$(LOCAL_PATH)/%=%)
LOCAL_LDLIBS := -lGLESv2 -llog
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := ignore_this_imajilib
LOCAL_STATIC_LIBRARIES := imajilib
include $(BUILD_SHARED_LIBRARY)
The ignore_this_imajilib
shared library module is a dependency trick I picked up from here.
I compile the library by cd'ing to the jni/
directory and running the following command:
~/path/to/ndk-build NDK_PROJECT_PATH=/path/to/<root> -B V=1
The compilation succeeds with no issues. I now have new directories libs/
and obj/
under the jni/
directory.
The structure of the libs/
directory is:
libs/
armeabi-v7a/
libignore_this_imajilib.so
This is okay but ideally I would like to see libimajilib.a
here as well.
The structure of the obj/
directory is:
obj/
local/
armeabi-v7a/
libignore_this_imajilib.so
libimajilib.a
objs/
imajilib/
<this directory is empty>
src/
<a bunch of *.o and *.o.d files>
The problem is with the location of the *.o
and *.o.d
files. I suspect the build process is placing them there because of the ../../src/*.c
that I have in the Android.mk
file, and so it is going to obj/local/armeabi-v7a/objs/imajilib/../../src
whereas I would like to see them in obj/local/armeabi-v7a/objs/imajilib
. I see no way around this other than to copy and paste the source files from src/
to the jni/
directory, but I don't want to do this as the src/
directory is shared among multiple platforms.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论