android建立NDK项目调用jrtplib与pc机进行通讯

按上两次的文章,编译好windows 平台(http://blog.csdn.net/nickwar/article/details/8962344)和android平台上使用的jrtplib库(http://blog.csdn.net/nickwar/article/details/8962482)之后,

就可以做进一步的应用开发了,但测试了一下发现,两边通讯不起来,

查资料发现,网络数据传输有大小端的区别(binendian和littleendian),

这就像是吃煮鸡蛋先从大头磕开还是小头磕开的问题,比较无聊,

但windows平台上编译的配置是默认littleendian的,但android(linux)上配置是默认大端的bigendian

所以,回到android平台编译的那一节,找到jrtplib源码目录下的CMakeLists.txt,打开它,

找到下面这段代码并注释其中相应的的行,重新编译即可获得littleendian的库

if (CMAKE_CROSSCOMPILING)
	# option (JRTPLIB_USE_BIGENDIAN "Target platform is big endian" ON)
	# if (JRTPLIB_USE_BIGENDIAN)
		# set(RTP_ENDIAN "#define RTP_BIG_ENDIAN")
	# else (JRTPLIB_USE_BIGENDIAN)
		set(RTP_ENDIAN "// Little endian system")
	# endif (JRTPLIB_USE_BIGENDIAN)
else (CMAKE_CROSSCOMPILING)
	# test_big_endian(JRTPLIB_BIGENDIAN)
	# if (JRTPLIB_BIGENDIAN)
		# set(RTP_ENDIAN "#define RTP_BIG_ENDIAN")
	# else (JRTPLIB_BIGENDIAN)
		set(RTP_ENDIAN "// Little endian system")
	# endif (JRTPLIB_BIGENDIAN)
endif (CMAKE_CROSSCOMPILING)


创建android ndk项目,

把上一节生成的android运行库libjrtplib.a, libthread和头文件拷到jni目录下,这里我使用的是静态库,

打开Anroid.mk并编辑为如下内容:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE  := jthread
LOCAL_SRC_FILES := libjthread.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE  := jrtplib
LOCAL_SRC_FILES := libjrtplib.a
LOCAL_STATIC_LIBRARIES := jthread
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE    := HelloJni
LOCAL_SRC_FILES := HelloJni.cpp
LOCAL_STATIC_LIBRARIES := jthread jrtplib
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)


然后参考jrtplib自带的样例,编写android上的代码,不再细说


在pc上运行example1.exe

在android上运行编写好的代码即可


截图:

android建立NDK项目调用jrtplib与pc机进行通讯_第1张图片


android建立NDK项目调用jrtplib与pc机进行通讯_第2张图片



android代码在github上:

https://github.com/F-Sidney/HellojrtplibAndroid.git


你可能感兴趣的:(android,NDK,JRtplib)