eclipse-paho / paho.mqtt.android

MQTT Android
Other
2.93k stars 888 forks source link

no NetworkModule installed for scheme "mqtt" of URI "mqtt://..." #432

Open AnkurJagani opened 4 years ago

AnkurJagani commented 4 years ago

Please fill out the form below before submitting, thank

Android API Version Bug Seen on: Android API Version 28 (Android 9.0) (Tested on emulator device. i.e. Nexus 5 With Provided Google Play Feature)

Android Version Bug Seen on: Android Pie

Please also check that if you have found the bug in the Release version (1.1.1) that you check that it also exists in the Snapshot (1.1.2-SNAPSHOT) before raising a bug.

Description of Bug:

Steps to re-create

  1. init MQTT Client. MqttAndroidClient mqttAndroidClient = new MqttAndroidClient(this, "mqtt://test.mosquitto.org:1883", MqttClient.generateClientId());

  2. Connect to the initiated client.

    try {                 
            IMqttToken iMqttToken = mqttAndroidClient.connect();
            iMqttToken.setActionCallback(this);
        } catch (MqttException e) {
            e.printStackTrace();
        }
  3. That's it. I am facing error in below callback method.

    @Override
    public void onFailure(IMqttToken asyncActionToken, Throwable exception) {
        exception.printStackTrace();        
    }

    printStackTrace already shown as below.

Console Log output (if available):

2020-09-28 15:01:54.019 26720-26720/org.oves.mqttdemo W/System.err: java.lang.IllegalArgumentException: no NetworkModule installed for scheme "mqtt" of URI "mqtt://test.mosquitto.org:1883"
2020-09-28 15:01:54.020 26720-26720/org.oves.mqttdemo W/System.err:     at org.eclipse.paho.client.mqttv3.internal.NetworkModuleService.validateURI(NetworkModuleService.java:74)
2020-09-28 15:01:54.020 26720-26720/org.oves.mqttdemo W/System.err:     at org.eclipse.paho.client.mqttv3.MqttAsyncClient.<init>(MqttAsyncClient.java:574)
2020-09-28 15:01:54.020 26720-26720/org.oves.mqttdemo W/System.err:     at org.eclipse.paho.client.mqttv3.MqttAsyncClient.<init>(MqttAsyncClient.java:438)
2020-09-28 15:01:54.020 26720-26720/org.oves.mqttdemo W/System.err:     at org.eclipse.paho.client.mqttv3.MqttAsyncClient.<init>(MqttAsyncClient.java:322)
2020-09-28 15:01:54.020 26720-26720/org.oves.mqttdemo W/System.err:     at org.eclipse.paho.android.service.MqttConnection.connect(MqttConnection.java:289)
2020-09-28 15:01:54.020 26720-26720/org.oves.mqttdemo W/System.err:     at org.eclipse.paho.android.service.MqttService.connect(MqttService.java:329)
2020-09-28 15:01:54.020 26720-26720/org.oves.mqttdemo W/System.err:     at org.eclipse.paho.android.service.MqttAndroidClient.doConnect(MqttAndroidClient.java:467)
2020-09-28 15:01:54.020 26720-26720/org.oves.mqttdemo W/System.err:     at org.eclipse.paho.android.service.MqttAndroidClient.access$200(MqttAndroidClient.java:76)
2020-09-28 15:01:54.020 26720-26720/org.oves.mqttdemo W/System.err:     at org.eclipse.paho.android.service.MqttAndroidClient$MyServiceConnection.onServiceConnected(MqttAndroidClient.java:115)
2020-09-28 15:01:54.020 26720-26720/org.oves.mqttdemo W/System.err:     at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1730)
2020-09-28 15:01:54.020 26720-26720/org.oves.mqttdemo W/System.err:     at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1762)
2020-09-28 15:01:54.020 26720-26720/org.oves.mqttdemo W/System.err:     at android.os.Handler.handleCallback(Handler.java:873)
2020-09-28 15:01:54.020 26720-26720/org.oves.mqttdemo W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:99)
2020-09-28 15:01:54.020 26720-26720/org.oves.mqttdemo W/System.err:     at android.os.Looper.loop(Looper.java:193)
2020-09-28 15:01:54.021 26720-26720/org.oves.mqttdemo W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:6669)
2020-09-28 15:01:54.021 26720-26720/org.oves.mqttdemo W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
2020-09-28 15:01:54.021 26720-26720/org.oves.mqttdemo W/System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
2020-09-28 15:01:54.021 26720-26720/org.oves.mqttdemo W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

Setup or Configuration of Library

  1. Inside application module build.gradle file.
    
    repositories {
    maven {
        url "https://repo.eclipse.org/content/repositories/paho-releases/"
    }
    }

implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.5' implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'


2. Inside `AndroidManifest.xml` file.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

<application>
<service android:name="org.eclipse.paho.android.service.MqttService" />
</application>


**_Although, it's simple to reproduce the issue, please let me know if you need my help to reproduce it._**
baowenqing commented 4 years ago

Has the problem been solved?

june5753 commented 3 years ago

You can do like this: Inside proguard.cfg file,add this -keep class org.eclipse.paho.client.mqttv3.internal. { ; } -keep class org.eclipse.paho.client.mqttv3.spi. { ; }

Good luck!

marclee44 commented 3 years ago

Connect to EMQ, please replace mqtt to tcp, like this:MqttAndroidClient mqttAndroidClient = new MqttAndroidClient(this, "tcp://test.mosquitto.org:1883", MqttClient.generateClientId()); Only 5 protocol supported: tcp/ssl/local/ws/wss

shenhejia commented 1 year ago

Connect to EMQ, please replace mqtt to tcp, like this:MqttAndroidClient mqttAndroidClient = new MqttAndroidClient(this, "tcp://test.mosquitto.org:1883", MqttClient.generateClientId()); Only 5 protocol supported: tcp/ssl/local/ws/wss

and replase 'mqtts' to 'ssl' ??