开发者

Precompiling static library in Android NDK - sources in separate directory tree

开发者 https://www.devze.com 2023-04-06 10:16 出处:网络
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

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 开发者_如何学Cset 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号