在android上使用pjsip时未定义的引用

时间:2014-01-29 10:09:29

标签: android android-ndk java-native-interface static-linking pjsip

我使用ndk_build生成存储在项目目录中的pjsip_lib文件夹中的静态库。 android.mk文件存在于jni文件夹中,如下所示:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := libpj-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := ../pjsip_lib/libpj-arm-unknown-linux-androideabi.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libpjlib-util-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := ../pjsip_lib/libpjlib-util-arm-unknown-linux-androideabi.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libpjmedia-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := ../pjsip_lib/libpjmedia-arm-unknown-linux-androideabi.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libpjmedia-audiodev-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := ../pjsip_lib/libpjmedia-audiodev-arm-unknown-linux-androideabi.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libpjmedia-codec-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := ../pjsip_lib/libpjmedia-codec-arm-unknown-linux-androideabi.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libpjmedia-videodev-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := ../pjsip_lib/libpjmedia-videodev-arm-unknown-linux-androideabi.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libpjnath-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := ../pjsip_lib/libpjnath-arm-unknown-linux-androideabi.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libpjsdp-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := ../pjsip_lib/libpjsdp-arm-unknown-linux-androideabi.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libpjsip-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := ../pjsip_lib/libpjsip-arm-unknown-linux-androideabi.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libpjsip-simple-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := ../pjsip_lib/libpjsip-simple-arm-unknown-linux-androideabi.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libpjsip-ua-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := ../pjsip_lib/libpjsip-ua-arm-unknown-linux-androideabi.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libpjsua2-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := ../pjsip_lib/libpjsua2-arm-unknown-linux-androideabi.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libpjsua-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := ../pjsip_lib/libpjsua-arm-unknown-linux-androideabi.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := dummy_pjsip_jni_module
LOCAL_SRC_FILES := com_example_voiper_NativeFunction.c
#LOCAL_LDLIBS += -lpj-arm-unknown-linux-androideabi -lpjlib-util-arm-unknown-linux-androideabi -lpjmedia-arm-unknown-linux-androideabi -lpjmedia-audiodev-arm-unknown-linux-androideabi  -lpjmedia-codec-arm-unknown-linux-androideabi -lpjmedia-videodev-arm-unknown-linux-androideabi -lpjnath-arm-unknown-linux-androideabi -lpjsdp-arm-unknown-linux-androideabi -lpjsip-arm-unknown-linux-androideabi -lpjsip-simple-arm-unknown-linux-androideabi -lpjsip-ua-arm-unknown-linux-androideabi -lpjsua2-arm-unknown-linux-androideabi -lpjsua-arm-unknown-linux-androideabi
LOCAL_EXPORT_C_INCLUDES += $(LOCAL_PATH)/include
LOCAL_C_INCLUDES += $(LOCAL_PATH)/include
LOCAL_STATIC_LIBRARIES :=  libpj-arm-unknown-linux-androideabi libpjlib-util-arm-unknown-linux-androideabi libpjmedia-arm-unknown-linux-androideabi libpjmedia-audiodev-arm-unknown-linux-androideabi  libpjmedia-codec-arm-unknown-linux-androideabi libpjmedia-videodev-arm-unknown-linux-androideabi libpjnath-arm-unknown-linux-androideabi libpjsdp-arm-unknown-linux-androideabi libpjsip-arm-unknown-linux-androideabi libpjsip-simple-arm-unknown-linux-androideabi libpjsip-ua-arm-unknown-linux-androideabi libpjsua2-arm-unknown-linux-androideabi libpjsua-arm-unknown-linux-androideabi
LOCAL_SHARED_LIBRARIES +=
include $(BUILD_SHARED_LIBRARY)

正如我们目前所见,只有一个c文件的内容如下:

JNIEXPORT jint JNICALL Java_com_example_voiper_NativeFunction_jniTest(JNIEnv* env, jobject thiz)
{
  app_init();
  return 30;
}

pj_str_t getLogFileName()
{
char *name = "./pj_log.txt";
return pj_str(name);
}

static pj_status_t app_init(void)
{
pjsua_config ua_cfg;
pjsua_logging_config log_cfg;
pjsua_media_config media_cfg;
pj_status_t status;
getLogFileName();
    //pjsua_create();
}

如果我取消注释pjsua_create调用,那么有很多未定义的引用..当我尝试执行ndk-build时所有错误..我在执行ndk-build时另外添加APP_PLATFORM = android-9 ..错误示例:

     in function pjsua_call_on_tsx_state_changed:pjsua_call.c(.text+0xb9d8): error: undefined reference to 'pjsip_tsx_send_msg'

为什么会这样?任何指针/解释?

编辑2:

根据建议,我更改了库的导入顺序(基于make install生成的pkgconfig):

    LOCAL_STATIC_LIBRARIES := pjsua pjsip-ua pjsip-simple pjsip pjmedia-codec pjmedia pjmedia-videodev pjmedia-audiodev pjnath pjlib-util milenage srtp resample gsm-codec speex ilbc-codec g7221-codec pj

错误数量已减少,仅来自libpjmedia-audiodev库。错误的一个例子:

        ANDROID_NDK_HOME/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: jni/../pjsip_lib/libpjmedia-audiodev-arm-unknown-linux-androideabi.a(opensl_dev.o): in function opensl_create_stream:opensl_dev.c(.text+0x1a2c): error: undefined reference to 'SL_IID_RECORD'

我尝试使用pkgconfig进行交叉编译(请参阅http://trac.pjsip.org/repos/wiki/Getting_Started_Using上的第一个make文件)但是又有问题..

编辑3:

在编辑2中提到的订单更改后,我在ndk-build期间得到了不同的错误,对于两种情况,一种是APP_PLATFORM = android-10,另一种是APP_PLATFORM = android-9

如果是10,一些非常基本的功能(以及prev错误)会出现错误,例如:

          error: undefined reference to 'malloc
          error: undefined reference to 'srand48'
          error: undefined reference to 'ioctl'
          ANDROID_NDK_HOME/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ANDROID_NDK_HOME/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/libgcc.a(pr-support.o): in function _Unwind_GetTextRelBase:/s/ndk-toolchain/src/build/../gcc/gcc-4.6/libgcc/../gcc/config/arm/pr-support.c:400: error: undefined reference to 'abort'

FIX:

将OpenSLES添加到LOCAL_LDLIBS ..

0 个答案:

没有答案