当前位置: 首页 > news >正文

【MQTT(3)】开发一个客户端,QT-Android安卓手机版本

手机版本更加方便

生成安卓库

参考了这个代码

在编译Mosquitto以支持安卓平台时,主要涉及到使用Android NDK(Native Development Kit)进行交叉编译。环境的准备参考之前的博客【QT开发(17)】2023-QT 5.14.2实现Android开发

在这里插入图片描述
下载Mosquitto, https://github.com/eclipse/mosquitto.git

2. 编写或准备编译脚本

对于Mosquitto的编译,可能需要编写一个CMake或Makefile脚本来配置编译选项,以支持Android平台。这通常包括指定Android的目标架构(如armeabi-v7a、arm64-v8a等)、API级别、工具链等。

例如,可以创建一个名为mosquitto_android_cmake.sh的脚本,内容大致如下(注意:以下脚本仅为示例,具体参数需根据实际情况调整):

#!/bin/bash
CURRENT_DIR=$(dirname $(readlink -f $0))
rm -rf ./build
mkdir -p build
ANDROID_ABI="armeabi-v7a"
ANDROID_NDK="/var/files/yanyixiong/android-ndk-r21e"
cmake \-DANDROID_NDK=${ANDROID_NDK} \-DANDROID_ABI=${ANDROID_ABI} \-DANDROID_NATIVE_API_LEVEL=21 \-DANDROID_TOOLCHAIN_NAME="arm-linux-androideabi-4.9" \-DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" \-DWITH_TLS=OFF \-DWITH_THREADING=OFF \-H. -B./build
cd build
cmake --build .
cd ..
cmake -DANDROID_NDK=/var/files/yanyixiong/android-ndk-r21e \ -DANDROID_ABI="armeabi-v7a" \-DCMAKE_TOOLCHAIN_FILE="/var/files/yanyixiong/android-ndk-r21e/build/cmake/android.toolchain.cmake"  \-DWITH_TLS=OFF \-DWITH_THREADING=OFF \-DCMAKE_C_FLAGS='-fPIC' \..

问题来了

目前来说,不支持ndk21版本

ndk 10版本

git clone https://github.com/eclipse/mosquitto.git
cd mosquitto
mkdir _build_android
cd _build_android
cmake -DANDROID_NDK=/opt/android-ndk/android-ndk-r10e -DANDROID_ABI="armeabi-v7a" -DANDROID_NDK_HOST_X64="YES"  -DANDROID_TOOLCHAIN_NAME="arm-linux-androideabi-4.9" -DCMAKE_TOOLCHAIN_FILE="/opt/android-ndk/build/cmake/android.toolchain.cmake" -DWITH_TLS=OFF -DWITH_THREADING=OFF -DCMAKE_C_FLAGS='-fPIC' ..

ndk-r8e

参考

#!/bin/bash
# Script used to cmake and then make mosquitto for android on MacOSX with android-ndk-r8e and a patched mosquitto source.
# Update paths below and run it from inside the root mosquitto dir (right in the one you clone from hg)# Used patched mosquitto from: https://bitbucket.org/andreasjk/mosquitto
# Used NDK: http://dl.google.com/android/ndk/android-ndk-r8e-darwin-x86_64.tar.bz2
# Used cmake toolchain file from https://github.com/Itseez/opencv/blob/master/android/android.toolchain.cmake# Threading has to be disabled since android doesn't support it fully
# Also disabled TLS since I couldn't get cmake to find the openssl lib properly
CURRENT_DIR=$(dirname $(readlink -f $0))
ANDROID_ABI="armeabi-v7a"
rm -rf mosquitto/build
mkdir -p mosquitto/build
cd mosquitto/build
cmake \-DANDROID_NDK=${ANDROID_NDK} \-DANDROID_ABI=${ANDROID_ABI} \-DANDROID_NDK_HOST_X64="YES" \-DANDROID_NATIVE_API_LEVEL=19 \-DANDROID_TOOLCHAIN_NAME="arm-linux-androideabi-4.9" \-DCMAKE_TOOLCHAIN_FILE="${CURRENT_DIR}/android-cmake/android.toolchain.cmake" \-DOPENSSL_LIBRARIES="${CURRENT_DIR}/openssl/arch-${ANDROID_ABI}/lib" \-DOPENSSL_INCLUDE_DIR="${CURRENT_DIR}/openssl/sources/include" \-DWITH_TLS=ON \-DWITH_THREADING=OFF ..
echo "Start building android ..."
make
echo "Output file `pwd`"
cd ..

r16b

If you want to use mosquitto on Android platforms, then you should use Android NDK to cross-compile the source for Android platforms.

Before start compiling, you should download Android NDK from Google official website. In addition, you should make sure that the version of cmake on your device is above 3.6.0. We suggest you use linux to do the following things.

Firstly, edit {SOURCE_DIR}/CMakeLists.txt and add following commands:

add_compile_options(-fPIE)
add_compile_options(-fPIC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pie")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pie")

after

add_definitions (-DCMAKE -DVERSION=\"${VERSION}\")

Secondly, enter the source folder({SOURCE_DIR}), and setup the build configure using the command below:

cmake -DANDROID_NDK=/home/sususweet/android_things/android-ndk-r16b -DANDROID_ABI="armeabi-v7a" -DANDROID_NDK_HOST_X64="YES"  -DANDROID_TOOLCHAIN_NAME="arm-linux-androideabi-4.9" -DCMAKE_TOOLCHAIN_FILE="/home/sususweet/android_things/android-ndk-r16b/build/cmake/android.toolchain.cmake" -DWITH_TLS=OFF -DWITH_THREADING=OFF -H. -B./build

Then go into build folder:

cd build

Use cmake to compile the source code:

cmake --build .

Then you can find built mosquitto in {SOURCE_DIR}/build folder.

5.14.4 必须是ndk20,没法编译

在这里插入图片描述在这里插入图片描述

如果想继续,就必须变更版本。就此作罢,写个笔记避避坑

http://www.lryc.cn/news/402374.html

相关文章:

  • 大数据之数据抽取架构演变过程
  • [web]-反序列化-绕过__wakeup(转)
  • B树与B+树的区别
  • 机器人开源调度系统OpenTCS-6最新版本地源码运行
  • 云监控(华为) | 实训学习day3(10)
  • springMVC前后端请求参数绑定和传递
  • 【iOS】—— 消息传递和消息转发
  • 【Node.js】初识 Node.js
  • AWS backup服务和 RDS snapshot的关系
  • PDF转Word怎么快速转换?格式转换技巧分享
  • 浅谈:网络协议及网络连接
  • websocket-react使用
  • 【总结】nginx源码编译安装报错./configure: error: SSL modules require the OpenSSL library.
  • 昇思25天学习打卡营第15天|两个分类实验
  • 实践:Redis6.0配置文件解读
  • 【Go系列】Go语言的网络服务
  • CS110L(Rust)
  • 免费恢复软件有哪些?电脑免费使用的 5 大数据恢复软件
  • Flink History Server配置
  • ASPICE过程改进原则:确保汽车软件开发的卓越性能
  • HDU1005——Number Sequence,HDU1006——Tick and Tick,HDU1007——Quoit Design
  • uniapp form表单校验
  • 构建RSS订阅机器人:观察者模式的实践与创新
  • 芯片基础 | `wire`类型引发的学习
  • 如何在AWS上构建Apache DolphinScheduler
  • Quartus II 13.1添加新的FPGA器件库
  • 【html】html的基础知识(面试重点)
  • Java 网络编程(TCP编程 和 UDP编程)
  • STM32 | 看门狗+RTC源码解析
  • filebeat,kafka,clickhouse,ClickVisual搭建轻量级日志平台