hivemq / hivemq-mqtt-client

HiveMQ MQTT Client is an MQTT 5.0 and MQTT 3.1.1 compatible and feature-rich high-performance Java client library with different API flavours and backpressure support
https://hivemq.github.io/hivemq-mqtt-client/
Apache License 2.0
847 stars 158 forks source link

Android API < 24 support does not work after migrating to AGP 7.2.1 #533

Open symphonybiz opened 2 years ago

symphonybiz commented 2 years ago

Expected behavior

If I follow the guide for supporting Android API below 24 here: https://hivemq.github.io/hivemq-mqtt-client/docs/installation/android/#android-api-levels-below-24

then using the mqtt client crashes at run time: java.lang.NoSuchMethodError: No interface method ... depending the specific method call

that didn't seem to happen before upgrading the Android Gradle Plugin to version 7.2.1: https://developer.android.com/studio/releases/gradle-plugin#7-2-0

Actual behavior

I am able to use the MQTT client without runtime exceptions

To Reproduce

Steps

Details

SgtSilvio commented 2 years ago

Hi @symphonybiz Can you provide more details, like a full stack trace or logs from the build?

denebchorny commented 2 years ago

Hi, the same here. This is my case:

ERROR 2022-07-21 20:22:00.313 31502-31502/com.hipcam.android.hipcam.uat E/AndroidRuntime: FATAL EXCEPTION: main Process: com.hipcam.android.hipcam.uat, PID: 31502 java.lang.NoSuchMethodError: No interface method publishes(Lcom/hivemq/client/mqtt/MqttGlobalPublishFilter;Ljava/util/function/Consumer;)V in class Lcom/hivemq/client/mqtt/mqtt5/Mqtt5AsyncClient; or its super classes (declaration of 'com.hivemq.client.mqtt.mqtt5.Mqtt5AsyncClient' appears in /data/app/~~T15tRmt6asnCaPP8wbCXGg==/com.hipcam.android.hipcam.uat-fiy5-UEmIwSvgXe-D448uA==/base.apk!classes17.dex) at com.hipcam.android.hipcam.core.mqtt.MQTT.build(MQTT.kt:133) at com.hipcam.android.hipcam.core.mqtt.MQTT.connectWithCredential(MQTT.kt:305) at com.hipcam.android.hipcam.core.mqtt.MQTT.connect(MQTT.kt:167) at com.hipcam.android.hipcam.di.App.setupMQTT(App.kt:132) at com.hipcam.android.hipcam.di.App.onStart(App.kt:100) at androidx.lifecycle.FullLifecycleObserverAdapter.onStateChanged(FullLifecycleObserverAdapter.java:39) at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:360) at androidx.lifecycle.LifecycleRegistry.forwardPass(LifecycleRegistry.java:271) at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:313) at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:151) at androidx.lifecycle.LifecycleRegistry.handleLifecycleEvent(LifecycleRegistry.java:134) at androidx.lifecycle.ProcessLifecycleOwner.activityStarted(ProcessLifecycleOwner.java:112) at androidx.lifecycle.ProcessLifecycleOwner$3$1.onActivityPostStarted(ProcessLifecycleOwner.java:177) at android.app.Activity.dispatchActivityPostStarted(Activity.java:1396) at android.app.Activity.performStart(Activity.java:8268) at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3872) at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221) at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201) at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2336) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:246) at android.app.ActivityThread.main(ActivityThread.java:8653) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

CALING THIS CAUSES THE CRASH ` mqtt = Mqtt5Client.builder() .identifier(identifier()) .serverHost(serverHost) .serverPort(serverPort) .addConnectedListener { onMQTTConnected(it) } .addDisconnectedListener { onMQTTDisconnected(it) } .buildAsync()

    mqtt?.publishes(MqttGlobalPublishFilter.SUBSCRIBED) { onConsumingTopic(it) }

`

As @symphonybiz suggested, the issue occurs when upgrading AGP

I changed distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip with distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip