android - 无法解决依赖关系。没有匹配的变体

标签 android gradle build.gradle algolia instantsearch-android

我在 Android 项目中遇到由以下依赖项引起的构建错误:
实现“com.algolia:instantsearch-android:2.5.1”
它有助于升级到 2.8.0,但我不想升级,因为它需要 minSdk 21。

Gradle 6.5
Android Gradle 插件:4.0.2
Kotlin 1.3.72

Could not determine the dependencies of task ':app:compileReleaseJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:releaseCompileClasspath'.
   > Could not resolve com.algolia:algoliasearch-client-kotlin-common:1.4.0.
     Required by:
         project :app > com.algolia:instantsearch-android:2.5.1
      > No matching variant of com.algolia:algoliasearch-client-kotlin-common:1.4.0 was found. The consumer was configured to find an API 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' but:
          - Variant 'metadata-api' capability com.algolia:algoliasearch-client-kotlin-common:1.4.0:
              - Incompatible because this component declares a usage of 'kotlin-api' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'common' and the consumer needed an API of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm'
              - Other compatible attribute:
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'release')

最佳答案

我的情况有点类似,但我的情况与您的情况略有不同。我将解释我的情况与您的情况之间的差异,以及我将如何纠正这种情况。这可能是解决您的问题的线索,但我会留给您看看它是否适用或有帮助。

在我的例子中,关于不兼容性的错误表明消费者有一个属性“org.jetbrains.kotlin.platform.type”,其值为“androidJvm”,并且它发现我的依赖项有一个属性“org.jetbrains”。 kotlin.platform.type' 的值为 'jvm'。请注意,我没有确切的文本,消息中谈到了其他属性和组件。但是当我解析消息时,明显的区别是“androidJvm”和“jvm”。

我做错了什么,是我试图将 android 库依赖项添加到 java 库,当然,这是不允许的。我已将“java-library”插件应用于依赖项,而不是将“com.android.plugin”应用于该库。我在离开时纠正了这个问题。

在你的例子中,看起来你有“common”和“androidJvm”的区别。不幸的是,我不知道平台类型“common”指的是什么。这可能是由于您应用的插件类型所致。希望这对您有所帮助!

关于android - 无法解决依赖关系。没有匹配的变体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66241227/

相关文章:

java - 如何修改我的代码以使用前置摄像头扫描二维码

android - 如何修改IP和端口使用react-native Android?

Android zxing journeyapps 条形码扫描器内部 fragment

java - ReflectionsException : Could not get type for name org. gradle.api.Plugin

Android Gradle 3.0.0 - 为特定风格添加库依赖

android - 如何在 headless linux 中更新 Android 平台工具?

java - Xmlbeans setter 在 gradle 测试中不起作用

java - Gradle - 更改 jar 的名称

Gradle 文件树懒惰的平面复制

java - Spring Boot + Gradle - 在哪里放置环境配置?