-
Notifications
You must be signed in to change notification settings - Fork 235
Open
Description
Hello, I have a problem with Android 7 with Base64 method from 'org.apache.commons.codec.binary.Base64'. I tested with com.microsoft.azure.sdk.iot:iot-service-client:1.28.0 and com.microsoft.azure.sdk.iot:iot-service-client:2.1.6, and both throw the same exception :(
Code
Using iot-service-client:1.28.0 and It is practically the same as the current version (2.1.6):
class IoTHubClient {
private fun getDevice(deviceId: String, connection: String): Device? {
val registry = RegistryManager.createFromConnectionString(connection)
return try {
registry.getDevice(deviceId)
} catch (e: IotHubNotFoundException) {
registry.addDevice(Device.createDevice(deviceId, AuthenticationType.SAS))
} catch (e: Exception) {
e.printStackTrace()
null
}
}
fun setup(deviceId: String, connection: String) {
// ...
val device = getDevice(deviceId, connection)
?: throw IotHubNotFoundException("Device not found")
// ...
}
}
Exception (iot-service-client:1.28.0):
java.lang.NoSuchMethodError: No static method encodeBase64String([B)Ljava/lang/String; in class Lorg/apache/commons/codec/binary/Base64; or its super classes (declaration of 'org.apache.commons.codec.binary.Base64' appears in /system/framework/org.apache.http.legacy.boot.jar)
at com.microsoft.azure.sdk.iot.service.auth.IotHubServiceSasToken.buildToken(IotHubServiceSasToken.java:99)
at com.microsoft.azure.sdk.iot.service.auth.IotHubServiceSasToken.<init>(IotHubServiceSasToken.java:68)
at com.microsoft.azure.sdk.iot.service.RegistryManager.getDevice(RegistryManager.java:230)
Exception (iot-service-client:2.1.6):
java.lang.NoSuchMethodError: No static method encodeBase64String([B)Ljava/lang/String; in class Lorg/apache/commons/codec/binary/Base64; or its super classes (declaration of 'org.apache.commons.codec.binary.Base64' appears in /system/framework/org.apache.http.legacy.boot.jar)
at com.microsoft.azure.sdk.iot.service.auth.IotHubServiceSasToken.buildToken(IotHubServiceSasToken.java:117)
at com.microsoft.azure.sdk.iot.service.auth.IotHubServiceSasToken.<init>(IotHubServiceSasToken.java:81)
at com.microsoft.azure.sdk.iot.service.auth.IotHubServiceSasToken.<init>(IotHubServiceSasToken.java:54)
at com.microsoft.azure.sdk.iot.service.registry.RegistryClient.getAuthenticationToken(RegistryClient.java:713)
at com.microsoft.azure.sdk.iot.service.registry.RegistryClient.createRequest(RegistryClient.java:693)
at com.microsoft.azure.sdk.iot.service.registry.RegistryClient.getDevice(RegistryClient.java:205)
Context
- Build Gradle dependencies:
// IOT Hub Service Client
implementation('org.apache.commons:commons-lang3:3.6')
implementation("com.microsoft.azure.sdk.iot:iot-device-client:1.28.0")
implementation("com.microsoft.azure.sdk.iot:iot-service-client:1.28.0")
implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'
- Android version: Android 7.0 (API level 24)
- Java runtime:
JavaVersion.VERSION_17 - Extra: I tested it in Android API level 24, 26, 28 and 30, it problem is only in versions lower than Android 9 (API level 28)