0

I have used ndk_build to generate static libraries stored in pjsip_lib folder inside the project directory. The android.mk file is present inside jni folder and is as follows:

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)

As we can see currently there is only a single c file whose content is as follows:

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();
}

If I uncomment the pjsua_create call then there are lots of undefined references.. all errors when i try to do ndk-build.. i additionally add APP_PLATFORM=android-9 when doing ndk-build.. example of an error:

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

Why is it happening? Any pointers/explanations?

EDIT 2:

As suggested I changed the import order of libraries (based on pkgconfig which is generated by make install):

    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

The number of errors have reduced and are only from libpjmedia-audiodev library. One example of the error:

        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'

I tried cross compiling too using pkgconfig (see first make file at http://trac.pjsip.org/repos/wiki/Getting_Started_Using) but again there were issues..

EDIT 3:

After the order change as mentioned in EDIT 2, Im getting different errors while during ndk-build, for two cases, one with APP_PLATFORM=android-10 and other with APP_PLATFORM=android-9

In case of 10, errors are coming for some very basic functions (along with prev errors), like :

          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:

add OpenSLES to LOCAL_LDLIBS..

singhsumit
  • 964
  • 1
  • 9
  • 26
  • Do you load your shared library on java side? – eozgonul Jan 29 '14 at 10:55
  • no.. i use idea ide which might be doing some magic.. how to do it? pointers? – singhsumit Jan 29 '14 at 11:08
  • also my ndk-build is failing (from command-line).. so java is probably not in picture.. since we have not created .so file yet – singhsumit Jan 29 '14 at 11:09
  • You are right, Java is not in the picture. If the static libraries are OK on NDK side, the problem might be related to the ordering of the static libraries. If library A depends on library B, then you have to load library B first. – eozgonul Jan 29 '14 at 11:24
  • so order matters in android.mk? i also am not aware if a static library depends on other static library and that too which one.. this dependency should be a part of android.mk.. is it? Also what if there is cyclic dependency? – singhsumit Jan 29 '14 at 11:59
  • 1
    Look at the error code you posted. It says that function pjsua_call_on_tsx_state_changed:pjsua_call.c has an undefined reference to pjsip_tsx_send_msg which brings down this issue: The library depends on another library. I think there is no easy way to do this, you can search for in which library that function is declared and load that function first. This should give you more of an explanation: http://stackoverflow.com/questions/4765465/android-ndk-two-static-libraries-and-linking – eozgonul Jan 29 '14 at 12:06
  • k.. yes im aware of that but somehow ignored it.. good point.. re-ordering has reduced my errors.. – singhsumit Jan 29 '14 at 12:36
  • You still get the same error? – eozgonul Jan 29 '14 at 12:53
  • no the number of errors have reduced drastically.. all from libpjmedia-audiodev library – singhsumit Jan 29 '14 at 13:01
  • thanks buddy.. finally its running for the present scenario.. – singhsumit Jan 29 '14 at 14:08
  • No problem, glad that it worked finally. – eozgonul Jan 29 '14 at 14:38

0 Answers0