React Native MQTT.js does not work on Android 9+

让人想犯罪 __ 提交于 2020-03-03 18:58:12

问题


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)

This is my build.gradle

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

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

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.


回答1:


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"

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



来源:https://stackoverflow.com/questions/59112767/react-native-mqtt-js-does-not-work-on-android-9

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!