Azure / azure-iot-sdk-java

A Java SDK for connecting devices to Microsoft Azure IoT services
https://azure.github.io/azure-iot-sdk-java/
Other
199 stars 236 forks source link

How to add azure-storage-blob with azure-sdk-bom in build.gradle #1794

Closed Shahanshah-TA closed 1 month ago

Shahanshah-TA commented 1 month ago

Hi I am creating a package using SDK from here to use it in React Native. I am not very familiar with Android part. I want to use File-upload-sample for that I need to add implementation com.azure:azure-storage-blob:12.8.0 and I found out that I have to use BOM as well as per this docs. After modification my build.gradle look like this

buildscript {
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath "com.android.tools.build:gradle:7.2.1"
    }
}

plugins {
    id "io.spring.dependency-management" version "1.0.15.RELEASE"
}

def reactNativeArchitectures() {
    def value = rootProject.getProperties().get("reactNativeArchitectures")
    return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
}

def isNewArchitectureEnabled() {
    return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
}

apply plugin: "com.android.library"

if (isNewArchitectureEnabled()) {
    apply plugin: "com.facebook.react"
}

def getExtOrDefault(name) {
    return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["AzureProvisionWithCertificate_" + name]
}

def getExtOrIntegerDefault(name) {
    return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["AzureProvisionWithCertificate_" + name]).toInteger()
}

def supportsNamespace() {
    def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
    def major = parsed[0].toInteger()
    def minor = parsed[1].toInteger()

    // Namespace support was added in 7.3.0
    return (major == 7 && minor >= 3) || major >= 8
}

android {
    if (supportsNamespace()) {
        namespace "com.azureprovisionwithcertificate"

        sourceSets {
            main {
                manifest.srcFile "src/main/AndroidManifestNew.xml"
            }
        }
    }

    compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")

    defaultConfig {
        minSdkVersion getExtOrIntegerDefault("minSdkVersion")
        targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
    }

    buildTypes {
        release {
            minifyEnabled false
        }
    }

    lintOptions {
        disable "GradleCompatible"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

repositories {
    mavenCentral()
    google()
}

dependencyManagement {
    imports {
        mavenBom "com.azure:azure-sdk-bom:1.2.8"
    }
}

dependencies {
    // For < 0.71, this will be from the local maven repo
    // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
    implementation "com.facebook.react:react-native:+"
    implementation 'com.squareup.okhttp3:okhttp:4.9.1'
    implementation 'org.bouncycastle:bcprov-jdk15on:1.70'
    implementation 'org.bouncycastle:bcmail-jdk15on:1.70'
    implementation 'com.microsoft.azure.sdk.iot:iot-device-client:2.5.0'
    implementation 'com.microsoft.azure.sdk.iot.provisioning.security:x509-provider:2.0.2'
    implementation 'com.microsoft.azure.sdk.iot.provisioning:provisioning-device-client:2.1.3'
    implementation 'com.azure:azure-storage-blob' // version will be managed by the BOM
}

And I am getting this error

* What went wrong:
Could not determine the dependencies of task ':app:processDebugResources'.
> Could not resolve all task dependencies for configuration ':app:debugRuntimeClasspath'.
   > Could not find com.azure:azure-storage-blob:.
     Required by:
         project :app > project :azure-provision-with-certificate

What I am doing wrong here? Do I need to manage dependencyManagement differently? Thank you

Shahanshah-TA commented 1 month ago

@timtay-microsoft