关于Adroid.mk的一个问题

时间:2011-08-12 07:06:43

标签: android java-native-interface shared android-ndk

我是Android NDK的新手。

有3个文件,“first.c,first.h,second.c” 我想编译成2个共享库(libfirst.so,libsecond.so,第二个使用第一个库)

bellow是 Android.mk

LOCAL_PATH:= $(call my-dir)


# first lib
include $(CLEAR_VARS)

LOCAL_MODULE    := libtwolib-first
LOCAL_SRC_FILES := first.c

include $(BUILD_SHARED_LIBRARY)

# second lib
#
include $(CLEAR_VARS)

LOCAL_MODULE    := libtwolib-second
LOCAL_SRC_FILES := second.c

LOCAL_SHARED_LIBRARIES := libtwolib-first

include $(BUILD_SHARED_LIBRARY)

first.h

extern int first(int  x, int  y);

second.c

jint
Java_com_example_twolibs_TwoLibs_add( JNIEnv*  env,
                                      jobject  this,
                                      jint     x,
                                      jint     y )
{
    return first(x, y);
}

但是什么时候运行这个程序,应用程序被迫关闭。 如果首先编译为静态库。那没关系。就像相关的Android.mk一样:

LOCAL_PATH:= $(call my-dir)

# first lib, which will be built statically
#
include $(CLEAR_VARS)

LOCAL_MODULE    := libtwolib-first
LOCAL_SRC_FILES := first.c

include $(BUILD_STATIC_LIBRARY)

# second lib, which will depend on and include the first one
#
include $(CLEAR_VARS)

LOCAL_MODULE    := libtwolib-second
LOCAL_SRC_FILES := second.c

LOCAL_STATIC_LIBRARIES := libtwolib-first

include $(BUILD_SHARED_LIBRARY)

任何人都可以帮助我吗? 非常感谢...

1 个答案:

答案 0 :(得分:0)

我自己也很陌生,但据我所知,你只能拥有一个共享库。要使用多个库,请静态链接它们,然后从静态库中构建一个共享库。