Search code examples
androidazureazure-storageazure-iot-hubazure-java-sdk

Is FileUpload functionality for Azure IoT Java SDK possible on Android?


We've been trying to use the Azure IoT SDK for Java on Android (via Kotlin) to initiate blob file uploads. The process seems to hang after the SAS token is received and the call to the CloudBlockBlob constructor is made.

So I tried calling the constructor directly and discovered a dependency on javax.xml.stream.XMLOutputFactory by virtue of the dependency on the Azure Storage SDK v. 2.2 (suprisingly old!). The javax libraries AFAIK aren't easily incorporated on Android.

There is a separate Android storage SDK (which presumably doesn't have these dependencies), but including that in addition to the IoT SDK understandably results in a ton of Duplicate Class errors.

What's the way out of this? Fork the Azure IoT SDK for Java and replace the storage SDK reference with the Android version?


Solution

  • In the build.gradle in the app, please declare dependencies as follows to replace the azure-storage with azure-storage-android:

    implementation ('com.microsoft.azure.sdk.iot:iot-device-client:1.14.2'){
        exclude module: 'azure-storage'
    }
    implementation ('com.microsoft.azure.android:azure-storage-android:2.0.0@aar')
    implementation ('org.apache.commons:commons-lang3:3.6') 
    

    This is documented in our sample: https://github.com/Azure-Samples/azure-iot-samples-java/edit/master/iot-hub/Samples/device/AndroidSample/app/build.gradle

    Let us know if you run into more issues by filing a GitHub issue here.