In version 2.16.1, calling AWSIotMqttManager.connect causes NoClassDefFoundError below to be thrown. Version 2.16.0 doesn't have this problem. This is probably because 2.16.1 uses a newer paho version that causes this when Android API level is lower than 24 (https://github.com/eclipse/paho.mqtt.java/issues/633)
java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/net/ssl/SNIHostName;
at org.eclipse.paho.client.mqttv3.internal.SSLNetworkModule.start(SSLNetworkModule.java:139)
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:722)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.ClassNotFoundException: Didn't find class "javax.net.ssl.SNIHostName" on path: DexPathList[[zip file "/data/app/com.mercurio.ganimedes-1/base.apk"],nativeLibraryDirectories=[/data/app/com.mercurio.ganimedes-1/lib/arm, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at org.eclipse.paho.client.mqttv3.internal.SSLNetworkModule.start(SSLNetworkModule.java:139)Â
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:722)Â
at java.lang.Thread.run(Thread.java:818)Â
Suppressed: java.lang.ClassNotFoundException: javax.net.ssl.SNIHostName
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 4 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
To Reproduce
Using Android with API level < 24
val mqtt = AWSIotMqttManager(clientId, CUSTOMER_SPECIFIC_ENDPOINT)
mqtt.keepAlive = 10
mqtt.isAutoReconnect = true
mqtt.setAutoResubscribe(true)
try {
mqtt.connect(keyStore) { status, throwable ->
Log.i(LOG_TAG, "AWS status = $status")
if (throwable != null) {
Log.e(LOG_TAG, "AWS IoT connection error", throwable)
} else if (status == AWSIotMqttClientStatusCallback.AWSIotMqttClientStatus.Connected) {
subscribe()
}
}
} catch (e: Exception) {
Log.e(LOG_TAG, "AWS IoT connection error", e)
}
Which AWS service(s) are affected?
IoT
Environment Information (please complete the following information):
@oliveira-marcello Thanks for reaching out. I will investigate and get back to you
same problem here. various devices but all with android 6
lib ver: 2.16.1
this changelog seams interesting:
AWS Android SDK for IoT now depends on the 1.2.2 version of the Paho Library org.eclipse.paho.client.mqttv3
https://developer.android.com/reference/javax/net/ssl/SNIHostName
this class is added in android 7.0
What is the status of this?
I'm developing an IoT app, and I'm not able to update the system. I'm stuck with API 22.
I don't want to use 2.16.0 forever when the lib is moving forward.
You have to either cut the support for older platforms officially or fix the issue either in your codebase or by contributing to Paho.
What's your plan?
@rynkowsg The Eclipse Paho Java project seriously lacks developers to fix the list of issues around race conditions, memory leaks and general stability - https://github.com/eclipse/paho.mqtt.java/issues
We moved to https://github.com/hivemq/hivemq-mqtt-client for this very reason.
@frittentheke In the latest master you still seem to use Eclipse Paho. When and where did you move to hivemq-mqtt-client?
@rynkowsg ah sorry, I am not part of this project nor referring to it ... in another project which required an MQTT library we moved to the mentioned hivemq-mqtt-client.
@rynkowsg Sorry for the inconvenience. There already seems to be a PR with a suggested fix. The PR seems to make sense to me. Not sure how long will it take for paho team to review and release it though. We are discussing this internally whether to wait for a fix in Paho or to look for an alternative. I do not have specific timeline that I can share at this point. I will let you know via an update on this thread as soon as there is any progress.
@desokroshan I'm afraid that if we wait for Paho, we might never close this issue.
If you look at the Paho repository, it doesn't look like someone was coming to solve any issues there.
The project is dying. The last commit is dated on 24 Sep 2019. The project's maintainer, Ian Craggs left IBM last year. He worked on Paho there. The Github user he used to use working on Paho no longer exist. He contributes now using a different account (@icraggs) but doesn't work on Java library.
January this year, he wrote a post http://modelbasedtesting.co.uk/2020/01/22/eclipse-paho-project-sponsorship-by-hivemq. Quotes:
This is why I suggest that organizations which have an interest in the survival of Paho to consider encouraging their own people to become more deeply involved in the project.
If there is insufficient interest to take actions to keep the project going then I am happy for the project or specific components, like the Java client, to be deprecated.
My reasoning is that the AWS SDK relies on an unmaintained/deprecated project. It is not good. Even for small projects, it is never good to use deprecated dependencies. Sooner or later it is going to be painful. Longer you wait, more painful it becomes.
This is AWS SDK. It is not a small project. All the more you should take action. Either by starting maintenance of the Paho Java library or by switching to an alternative that is maintained by 3rd party.
Hi @rynkowsg ,
Thank you for your concerns. I will discuss with the team to see how we can approach this issue from our side.
The Paho team pulled in https://github.com/eclipse/paho.mqtt.java/pull/666, and are intended to release in the next couple of weeks. We'll test this fix, add any documentation required, and get a release out shortly after that.
Hi guys, i got the same bug too.
and i fixed it in my project like the following setp:
clone the eclipse/paho.mqtt.java,
catch SNIServerName not found bug under Android 7 with #666
and use eclipse to make a new jar-- org.eclipse.paho.client.mqttv3-1.2.2.jar
copy the jar to libs in my project.
replace the implementation in the build.gradle like:
implementation("com.amazonaws:aws-android-sdk-iot:$aws_version") {
exclude module: 'org.eclipse.paho.client.mqttv3'
}
implementation files('libs/org.eclipse.paho.client.mqttv3-1.2.2.jar')
then it works under Android 7.
Hi @103style ,
Thank you for providing a temporary workaround for those in need of immediate support.
Fortunately, it appears that the PR #666 has been merged by the Paho project maintainer. We will continue to track this issue to update our Paho dependency as soon as it is made available so that you do not need to manually import the SDK jar file.
@raphkim Hi, org.eclipse.paho.client.mqttv3 v1.2.3 is released.
Why hasn't this problem been solved yet? After we updated the AWS SDK, there are many complaints about crashes under Android 7.0.
Hi @awc ,
We are currently working on improving our testing infrastructure, which caused a small delay in delivering a fix for this issue. We are still looking to resolve it as quickly as possible, so please hang on tight!
@raphkim Any update on this? As there are many users which are using Android lollipop and Marshmallow and reporting the same in very extensive level.
Another solution is to exclude a transitive paho dep and include a specific version manually:
def aws_version = "2.16.+"
implementation ("com.amazonaws:aws-android-sdk-iot:$aws_version"){
exclude group: 'org.eclipse.paho', module: 'org.eclipse.paho.client.mqttv3'
}
implementation "org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.4"
implementation "com.amazonaws:aws-android-sdk-mobile-client:$aws_version"
Edit: It seems that there are some other issues after updating to 1.2.3 as MQTT can't connect to aws anymore
Edit2: Version 1.2.4 seems to work fine
Any update on this issue? Our new project on AWS IoT also needs to support Android 6 devices, and this bug is blocking our release. Thanks.
Most helpful comment
@desokroshan I'm afraid that if we wait for Paho, we might never close this issue.
If you look at the Paho repository, it doesn't look like someone was coming to solve any issues there.
The project is dying. The last commit is dated on 24 Sep 2019. The project's maintainer, Ian Craggs left IBM last year. He worked on Paho there. The Github user he used to use working on Paho no longer exist. He contributes now using a different account (@icraggs) but doesn't work on Java library.
January this year, he wrote a post http://modelbasedtesting.co.uk/2020/01/22/eclipse-paho-project-sponsorship-by-hivemq. Quotes:
My reasoning is that the AWS SDK relies on an unmaintained/deprecated project. It is not good. Even for small projects, it is never good to use deprecated dependencies. Sooner or later it is going to be painful. Longer you wait, more painful it becomes.
This is AWS SDK. It is not a small project. All the more you should take action. Either by starting maintenance of the Paho Java library or by switching to an alternative that is maintained by 3rd party.