Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug Report] NoSuchMethodError: No static method encodeBase64String from Base64 #1742

Open
MacKey-255 opened this issue Sep 21, 2023 · 0 comments

Comments

@MacKey-255
Copy link

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant