关于Android NDK中如何调用第三方静态库--live555

最近一直在做Android上多媒体的开发,主要涉及到Android媒体框层,开始是移植live555和ffmpeg到Android上,改进Android多媒体框架Open Core的不足

附上Android体系架构图:

开始是移植出现各种错误,各种找资料,最后在Android上成功移植上了live555和ffmpeg,最近也忙于整合测试,没时间写写心得!

前几天在测试在Android上调用live555中的库,写了测试工程,其中jni中的Android.mk文件如下:

LOCAL_PATH := $(call my-dir)

 

include $(CLEAR_VARS)

 

LOCAL_SRC_FILES := \

 WMNetSdk/live555Android.cpp \

 

LOCAL_STATIC_LIBRARIES :=live555lib/libBasicUsageEnvironment.a \

 live555lib/libgroupsock.a \

 live555lib/libliveMedia.a \

 live555lib/libUsageEnvironment.a

 

#LOCAL_SHARED_LIBRARIES := libutils libdl  libstlport_shared  $(LOCAL_PATH)/live555lib/liblive555.so

LOCAL_SHARED_LIBRARIES := libutils libdl  libstlport_shared 

 

LOCAL_LDLIBS    := -llog -lz -lm

 

LOCAL_MODULE := NetSdkTest

 

LOCAL_ARM_MODE := arm

 

LOCAL_PRELINK_MODULE := false

 

LOCAL_CPPFLAGS := \

 -DNULL=0 -DSOCKLEN_T=socklen_t -DNO_SSTREAM -DBSD=1 -DNO_SSTREAM -fexceptions -DANDROID

 

LOCAL_C_INCLUDES := \

 $(LOCAL_PATH)/../../live555/jni/BasicUsageEnvironment/include \

 $(LOCAL_PATH)/../../live555/jni/UsageEnvironment/include \

 $(LOCAL_PATH)/../../live555/jni/groupsock/include \

 $(LOCAL_PATH)/../../live555/jni/liveMedia/include \

 /home/hu/android-ndk-r5b/sources/cxx-stl/stlport/stlport

 

 

LOCAL_MODULE_TAGS := optional

 

include $(BUILD_SHARED_LIBRARY)

 

libBasicUsageEnvironment.a libgroupsock.a libliveMedia.a libUsageEnvironment.a 是我要调用的第三方静态库,是我在Android NDK中编译的live555库,

关于为什么要在Android上移植live555,大家应该知道Android的多媒体核心框架Open Core对流媒体支持本身不太给力,移植ffmpeg和live555可以改进Android

的多媒体支持!

但是出现了问题,提示一直找不到静态库中的函数,如下提示:

报的是live555中的DELAY_QUENEN之类的错,还报live555中基础类的错误,我怀疑是调用live555的库出现问题,于是网上度狗(百度和谷歌),最后确定是

调用live555库的问题,Android.mk肯定写错了!

  

其中部分错误是公司内部库提供的函数。

找了很多资料没能解决问题,最终在网友:江南一叶的帮助下解决问题了,原因是静态库链接不对,将Android.mk改为:

LOCAL_PATH := $(call my-dir)

  

include $(CLEAR_VARS)   

LOCAL_MODULE    := BasicUsageEnvironment

LOCAL_SRC_FILES :=live555lib/libBasicUsageEnvironment.a

 

include $(PREBUILT_STATIC_LIBRARY)

 

include $(CLEAR_VARS)

LOCAL_MODULE    := groupsock

LOCAL_SRC_FILES :=live555lib/libgroupsock.a

include $(PREBUILT_STATIC_LIBRARY)

 

include $(CLEAR_VARS)

LOCAL_MODULE    := liveMedia

LOCAL_SRC_FILES :=live555lib/libliveMedia.a

include $(PREBUILT_STATIC_LIBRARY)

 

include $(CLEAR_VARS)

LOCAL_MODULE    := UsageEnvironment

LOCAL_SRC_FILES :=live555lib/libUsageEnvironment.a

include $(PREBUILT_STATIC_LIBRARY)

 

include $(CLEAR_VARS)

LOCAL_MODULE    := NetSdkTest

LOCAL_SRC_FILES := \

 WMNetSdk/live555Android.cpp

LOCAL_C_INCLUDES := \

 $(LOCAL_PATH)/../../live555/jni/BasicUsageEnvironment/include \

 $(LOCAL_PATH)/../../live555/jni/UsageEnvironment/include \

 $(LOCAL_PATH)/../../live555/jni/groupsock/include \

 $(LOCAL_PATH)/../../live555/jni/liveMedia/include \

 /home/hu/android-ndk-r5b/sources/cxx-stl/stlport/stlport

 

LOCAL_STATIC_LIBRARIES := BasicUsageEnvironment groupsock liveMedia UsageEnvironment

 

LOCAL_LDLIBS := -llog

 

include $(BUILD_SHARED_LIBRARY)

 

最后在Android NDK中编译测试库成功,在eclipse中编译整个测试工程成功,在Android中调用live555库成功连上局域网中的RTSP服务器,测试大告成功,
真的是纠结死了这些天,虽然碰到了问题,但最后成功了!



接下来,我准备把Android上移植ffmpeg和live555的文档整理一下,顺便把测试工程免积分共享一下,希望能帮上网上新手开始Android多媒体开发...

你可能感兴趣的:(嵌入式多媒体开发)