Skip to content

Instantly share code, notes, and snippets.

@realdadfish
Last active February 27, 2023 07:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save realdadfish/eb903f2a0832e023e1c4ec37929648ed to your computer and use it in GitHub Desktop.
Save realdadfish/eb903f2a0832e023e1c4ec37929648ed to your computer and use it in GitHub Desktop.
Unmatched attributes issue and solution
val configuration = project.configurations.getByName("prodConsumerReleaseRuntimeClasspath")
val artifactType = Attribute.of("artifactType", String::class.java)
// Some plugin can only work with configurations, while the Android Gradle Plugin (AGP) has the newer "artifact view"
// paradigm implemented. This makes it impossible to resolve most of the created, variant-aware
// configurations from AGP "by hand" without getting unmatched attribute exceptions.
// We now pick one artifact that holds our dependencies and add a custom compatibility rule
// for it which basically accepts all incoming compatibility issues as long as the produced value
// on "the other side" is a JAR or AAR artifact.
configuration.attributes {
attribute(artifactType, "android-classes-directory")
}
project.dependencies {
attributesSchema {
getMatchingStrategy(artifactType).compatibilityRules.add(AgpCompatibility::class.java)
}
}
class AgpCompatibility : AttributeCompatibilityRule<String> {
override fun execute(details: CompatibilityCheckDetails<String>) {
if (details.consumerValue == "android-classes-directory" &&
(details.producerValue == "aar" || details.producerValue == "jar")) {
details.compatible()
}
}
}
> Could not resolve all dependencies for configuration ':myapp:prodConsumerReleaseRuntimeClasspath'.
> The consumer was configured to find a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release', attribute 'environment' with value 'prod', attribute 'device' with value 'consumer', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm'. However we cannot choose between the following variants of project :mylib:
- Configuration ':mylib:releaseRuntimeElements' variant android-assets declares a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm':
- Unmatched attributes:
- Provides attribute 'artifactType' with value 'android-assets' but the consumer didn't ask for it
- Provides attribute 'com.android.build.api.attributes.VariantAttr' with value 'release' but the consumer didn't ask for it
- Doesn't say anything about device (required 'consumer')
- Doesn't say anything about environment (required 'prod')
- Configuration ':mylib:releaseRuntimeElements' variant android-classes-directory declares a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm':
- Unmatched attributes:
- Provides attribute 'artifactType' with value 'android-classes-directory' but the consumer didn't ask for it
- Provides attribute 'com.android.build.api.attributes.VariantAttr' with value 'release' but the consumer didn't ask for it
- Doesn't say anything about device (required 'consumer')
- Doesn't say anything about environment (required 'prod')
- Configuration ':mylib:releaseRuntimeElements' variant android-compiled-dependencies-resources declares a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm':
- Unmatched attributes:
- Provides attribute 'artifactType' with value 'android-compiled-dependencies-resources' but the consumer didn't ask for it
- Provides attribute 'com.android.build.api.attributes.VariantAttr' with value 'release' but the consumer didn't ask for it
- Doesn't say anything about device (required 'consumer')
- Doesn't say anything about environment (required 'prod')
- Configuration ':mylib:releaseRuntimeElements' variant android-consumer-proguard-rules declares a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm':
- Unmatched attributes:
- Provides attribute 'artifactType' with value 'android-consumer-proguard-rules' but the consumer didn't ask for it
- Provides attribute 'com.android.build.api.attributes.VariantAttr' with value 'release' but the consumer didn't ask for it
- Doesn't say anything about device (required 'consumer')
- Doesn't say anything about environment (required 'prod')
- Configuration ':mylib:releaseRuntimeElements' variant android-jni declares a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm':
- Unmatched attributes:
- Provides attribute 'artifactType' with value 'android-jni' but the consumer didn't ask for it
- Provides attribute 'com.android.build.api.attributes.VariantAttr' with value 'release' but the consumer didn't ask for it
- Doesn't say anything about device (required 'consumer')
- Doesn't say anything about environment (required 'prod')
- Configuration ':mylib:releaseRuntimeElements' variant android-manifest declares a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm':
- Unmatched attributes:
- Provides attribute 'artifactType' with value 'android-manifest' but the consumer didn't ask for it
- Provides attribute 'com.android.build.api.attributes.VariantAttr' with value 'release' but the consumer didn't ask for it
- Doesn't say anything about device (required 'consumer')
- Doesn't say anything about environment (required 'prod')
- Configuration ':mylib:releaseRuntimeElements' variant android-navigation-json declares a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm':
- Unmatched attributes:
- Provides attribute 'artifactType' with value 'android-navigation-json' but the consumer didn't ask for it
- Provides attribute 'com.android.build.api.attributes.VariantAttr' with value 'release' but the consumer didn't ask for it
- Doesn't say anything about device (required 'consumer')
- Doesn't say anything about environment (required 'prod')
- Configuration ':mylib:releaseRuntimeElements' variant android-public-res declares a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm':
- Unmatched attributes:
- Provides attribute 'artifactType' with value 'android-public-res' but the consumer didn't ask for it
- Provides attribute 'com.android.build.api.attributes.VariantAttr' with value 'release' but the consumer didn't ask for it
- Doesn't say anything about device (required 'consumer')
- Doesn't say anything about environment (required 'prod')
- Configuration ':mylib:releaseRuntimeElements' variant android-res declares a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm':
- Unmatched attributes:
- Provides attribute 'artifactType' with value 'android-res' but the consumer didn't ask for it
- Provides attribute 'com.android.build.api.attributes.VariantAttr' with value 'release' but the consumer didn't ask for it
- Doesn't say anything about device (required 'consumer')
- Doesn't say anything about environment (required 'prod')
- Configuration ':mylib:releaseRuntimeElements' variant android-symbol declares a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm':
- Unmatched attributes:
- Provides attribute 'artifactType' with value 'android-symbol' but the consumer didn't ask for it
- Provides attribute 'com.android.build.api.attributes.VariantAttr' with value 'release' but the consumer didn't ask for it
- Doesn't say anything about device (required 'consumer')
- Doesn't say anything about environment (required 'prod')
- Configuration ':mylib:releaseRuntimeElements' variant android-symbol-with-package-name declares a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm':
- Unmatched attributes:
- Provides attribute 'artifactType' with value 'android-symbol-with-package-name' but the consumer didn't ask for it
- Provides attribute 'com.android.build.api.attributes.VariantAttr' with value 'release' but the consumer didn't ask for it
- Doesn't say anything about device (required 'consumer')
- Doesn't say anything about environment (required 'prod')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment