hivemq / hivemq-mqtt-client

HiveMQ MQTT Client is an MQTT 5.0 and MQTT 3.1.1 compatible and feature-rich high-performance Java client library with different API flavours and backpressure support
https://hivemq.github.io/hivemq-mqtt-client/
Apache License 2.0
824 stars 153 forks source link

No matching variant of com.hivemq:hivemq-mqtt-client-websocket:1.3.3 was found #610

Closed digrec closed 4 months ago

digrec commented 6 months ago

🐛 Bug Report

After updating to Android Studio Hedgehog and AGP 8.2 my project fails to build with Could not resolve com.hivemq:hivemq-mqtt-client-websocket:1.3.3. and No matching variant of com.hivemq:hivemq-mqtt-client-websocket:1.3.3 was found. errors.

FAILURE: Build completed with 8 failures.

1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Could not resolve com.hivemq:hivemq-mqtt-client-websocket:1.3.3.
     Required by:
         project :app
      > No matching variant of com.hivemq:hivemq-mqtt-client-websocket:1.3.3 was found. The consumer was configured to find a library for use during runtime, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '8.2.0', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but:
          - Variant 'apiElements' capability com.hivemq:hivemq-mqtt-client-websocket:1.3.3:
              - Incompatible because this component declares a platform for use during compile-time and the consumer needed a library for use during runtime
              - Other compatible attributes:
                  - Doesn't say anything about com.android.build.api.attributes.AgpVersionAttr (required '8.2.0')
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
                  - Doesn't say anything about its target Java environment (preferred optimized for Android)
                  - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'androidJvm')
          - Variant 'enforcedApiElements' capability com.hivemq:hivemq-mqtt-client-websocket-derived-enforced-platform:1.3.3:
              - Incompatible because this component declares an enforced platform for use during compile-time and the consumer needed a library for use during runtime
              - Other compatible attributes:
                  - Doesn't say anything about com.android.build.api.attributes.AgpVersionAttr (required '8.2.0')
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
                  - Doesn't say anything about its target Java environment (preferred optimized for Android)
                  - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'androidJvm')
          - Variant 'enforcedRuntimeElements' capability com.hivemq:hivemq-mqtt-client-websocket-derived-enforced-platform:1.3.3 declares a component for use during runtime:
              - Incompatible because this component declares an enforced platform and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about com.android.build.api.attributes.AgpVersionAttr (required '8.2.0')
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
                  - Doesn't say anything about its target Java environment (preferred optimized for Android)
                  - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'androidJvm')
          - Variant 'runtimeElements' capability com.hivemq:hivemq-mqtt-client-websocket:1.3.3 declares a component for use during runtime:
              - Incompatible because this component declares a platform and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about com.android.build.api.attributes.AgpVersionAttr (required '8.2.0')
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
                  - Doesn't say anything about its target Java environment (preferred optimized for Android)
                  - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'androidJvm')

And 7 more times like this for every other gradle task.

🔬 How To Reproduce

  1. Create a new empty Android project using Android Studio Hedgehog.
  2. Add hivemq-mqtt-client and mqtt-client-websocket v1.3.3 as dependencies.
  3. Rebuild the project and see the build errors.

Note: this can't be reproduced with AGP 8.1.4!

Code sample

Project build.gradle

plugins {
    id 'com.android.application' version '8.2.0' apply false
    id 'org.jetbrains.kotlin.android' version '1.9.10' apply false
}

App build.gradle

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
}

android {
    namespace 'com.example.mqttclient'
    compileSdk 34

    defaultConfig {
        applicationId "com.example.mqttclient"
        minSdk 24
        targetSdk 34
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    packaging {
        resources.excludes += [
                'META-INF/INDEX.LIST',
                'META-INF/io.netty.versions.properties',
                'DebugProbesKt.bin',
        ]
    }
}

dependencies {

    implementation 'androidx.core:core-ktx:1.12.0'
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.google.android.material:material:1.11.0'
    implementation 'com.hivemq:hivemq-mqtt-client:1.3.3'
    implementation 'com.hivemq:hivemq-mqtt-client-websocket:1.3.3'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}

Environment

Android Studio Hedgehog | 2023.1.1 Build #AI-231.9392.1.2311.11076708, built on November 9, 2023 Runtime version: 17.0.7+0-17.0.7b1000.6-10550314 aarch64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. macOS 14.2

Xcreen commented 5 months ago

I got the same error after upgrading agp from 8.1.4 to 8.2.x.

digrec commented 4 months ago

Any update on this issue? This makes AGP 8.2+ unusable on MQTT projects, and AGP 8.3 is already out for new AS Iguana!

If anyone has a workaround for this, please share it here!

bddckr commented 4 months ago

I don't have this issue. I'm using com.hivemq:hivemq-mqtt-client-websocket:1.3.3 in an Android library project. AGP 8.3.0, Gradle 8.6.

digrec commented 4 months ago

In my empty app project, as in my first post, using AGP 8.3 with Gradle 8.4 or 8.6 does not help. Errors are the same:

FAILURE: Build completed with 12 failures.

1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Could not resolve com.hivemq:hivemq-mqtt-client-websocket:1.3.3.
     Required by:
         project :app
      > No matching variant of com.hivemq:hivemq-mqtt-client-websocket:1.3.3 was found. The consumer was configured to find a library for use during runtime, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '8.3.0', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but:
          - Variant 'apiElements' capability com.hivemq:hivemq-mqtt-client-websocket:1.3.3:
              - Incompatible because this component declares a platform for use during compile-time and the consumer needed a library for use during runtime
              - Other compatible attributes:
                  - Doesn't say anything about com.android.build.api.attributes.AgpVersionAttr (required '8.3.0')
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
                  - Doesn't say anything about its target Java environment (preferred optimized for Android)
                  - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'androidJvm')
          - Variant 'enforcedApiElements' capability com.hivemq:hivemq-mqtt-client-websocket-derived-enforced-platform:1.3.3:
              - Incompatible because this component declares an enforced platform for use during compile-time and the consumer needed a library for use during runtime
              - Other compatible attributes:
                  - Doesn't say anything about com.android.build.api.attributes.AgpVersionAttr (required '8.3.0')
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
                  - Doesn't say anything about its target Java environment (preferred optimized for Android)
                  - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'androidJvm')
          - Variant 'enforcedRuntimeElements' capability com.hivemq:hivemq-mqtt-client-websocket-derived-enforced-platform:1.3.3 declares a component for use during runtime:
              - Incompatible because this component declares an enforced platform and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about com.android.build.api.attributes.AgpVersionAttr (required '8.3.0')
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
                  - Doesn't say anything about its target Java environment (preferred optimized for Android)
                  - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'androidJvm')
          - Variant 'runtimeElements' capability com.hivemq:hivemq-mqtt-client-websocket:1.3.3 declares a component for use during runtime:
              - Incompatible because this component declares a platform and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about com.android.build.api.attributes.AgpVersionAttr (required '8.3.0')
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
                  - Doesn't say anything about its target Java environment (preferred optimized for Android)
                  - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'androidJvm')

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
==============================================================================

Gradle 8.6 just additionally points out to the docs for variant selection errors and some possible reasons: https://docs.gradle.org/8.6/userguide/variant_model.html#sub:variant-no-match

Try:
> Review the variant matching algorithm at https://docs.gradle.org/8.6/userguide/variant_attributes.html#sec:abm_algorithm.
> No matching variant errors are explained in more detail at https://docs.gradle.org/8.6/userguide/variant_model.html#sub:variant-no-match.
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
==============================================================================
SgtSilvio commented 4 months ago

Please replace implementation 'com.hivemq:hivemq-mqtt-client-websocket:1.3.3' with implementation(platform('com.hivemq:hivemq-mqtt-client-websocket:1.3.3'))

digrec commented 4 months ago

@SgtSilvio that's it, thank you! My bad for not checking the repo README.