React Native MQTT.js在Android 9+上不起作用 [英] React Native MQTT.js does not work on Android 9+

查看:183
本文介绍了React Native MQTT.js在Android 9+上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 React Native 0.61 (CLI)构建Android应用 并在此处使用常见的MQTT.js软件包: https://www.npmjs.com/package/mqtt (v.3.0.0)

I am building an Android app using React Native 0.61 (CLI) and use common MQTT.js packages here: https://www.npmjs.com/package/mqtt (v.3.0.0)

这是我的 build.gradle

buildToolsVersion = "28.0.3"
minSdkVersion = 25
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"

我使用 WebSocket 协议连接到自己的mqtt代理.

I use WebSocket protocol to connect to my own mqtt broker.

在调试模式下,所有功能均可在任何手机上完美运行.但是很奇怪,当我通过命令释放APK ( gradlew assembleRelease (已签名)),它无法连接到Android 9+(两个模拟器)上的代理(Android 8运行良好)

In debug mode, everything works perfectly on any phone. But weird that when I release APK by command (gradlew assembleRelease (signed)), it can not connect to the broker on Android 9+ (both emulator) (Android 8 work well)

编译为本机代码时似乎出现了问题.

It seems there was a problem when compiling to native code.

推荐答案

这可能是因为从Andoird 9开始不允许使用默认的HTTP.您可以在AndroidMainfest.xml中添加以下内容.

it may because the HTTP is default is disallowed since Andoird 9.you can add the following at the AndroidMainfest.xml.

<application
    android:usesCleartextTraffic="true"

您还可以使用配置XML.为此,您可以看到此博客

you can also use a config XML. for that you can see this blog

这篇关于React Native MQTT.js在Android 9+上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆