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_
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 15
    评论
使用Android Studio创建NDK项目的步骤如下: 1. 创建新项目:在Android Studio中选择“Start a new Android Studio project”。 2. 添加NDK支持:在“Add an Activity to Mobile”页面中,选择“Native C++”作为Activity类型,然后单击“Next”。 3. 配置C++支持:在“Customize C++ Support”页面中,选择“C++11”作为C++标准库,并选择“None”作为异常支持。单击“Finish”。 4. 配置gradle文件:在项目的build.gradle文件中,添加以下代码: ``` externalNativeBuild { cmake { path "CMakeLists.txt" } } ``` 5. 配置CMakeLists.txt文件:在项目的CMakeLists.txt文件中,添加以下代码: ``` cmake_minimum_required(VERSION 3.4.1) add_library( # Sets the name of the library. native-lib # Sets the library as a shared library. SHARED # Provides a relative path to your source file(s). src/main/cpp/native-lib.cpp ) # Searches for a specified prebuilt library and stores the path as a # variable. Because system libraries are included in the search path by # default, you only need to specify the name of the public NDK library # you want to add. CMake verifies that the library exists before # completing its build. find_library( # Sets the name of the path variable. log-lib # Specifies the name of the NDK library that # you want CMake to locate. log ) # Specifies libraries CMake should link to your target library. You # can link multiple libraries, such as libraries you define in the # build script, prebuilt third-party libraries, or system libraries. target_link_libraries( # Specifies the target library. native-lib # Links the target library to the log library # included in the NDK. ${log-lib} ) ``` 6. 编写C++代码:在src/main/cpp目录下创建native-lib.cpp文件,并添加以下代码: ``` #include <jni.h> #include <string> extern "C" JNIEXPORT jstring JNICALL Java_com_example_myapplication_MainActivity_stringFromJNI( JNIEnv* env, jobject /* this */) { std::string hello = "Hello from C++"; return env->NewStringUTF(hello.c_str()); } ``` 7. 在MainActivity.java文件中添加以下代码: ``` static { System.loadLibrary("native-lib"); } public native String stringFromJNI(); ``` 8. 运行应用程序:构建并运行应用程序,您将看到“Hello from C++”消息。 --相关问题--: 1. 如何在Android Studio中使用OpenCV? 2. 如何在NDK中使用CMake? 3.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 15
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值