gradle错误:ERROR: Cannot choose between the following configurations of project :logic:

博客主要围绕Android studio升级到3.0后出现的报错展开。报错信息为“Error:Cannot choose between the following configurations of project”,原因是升级导致apt失效,不过文档未提及具体解决办法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考:Android studio升级3.0,提示“Error:Cannot choose between the following configurations of project”错误

项目报错:

ERROR: Cannot choose between the following configurations of project :logic:
  - debugApiElements
  - debugRuntimeElements
  - releaseApiElements
  - releaseRuntimeElements
All of them match the consumer attributes:
  - Configuration 'debugApiElements':
      - Found com.android.build.api.attributes.BuildTypeAttr 'debug' but wasn't required.
      - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.
      - Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
      - Found org.gradle.api.attributes.Usage 'java-api' but wasn't required.
  - Configuration 'debugRuntimeElements':
      - Found com.android.build.api.attributes.BuildTypeAttr 'debug' but wasn't required.
      - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.
      - Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
      - Found org.gradle.api.attributes.Usage 'java-runtime' but wasn't required.
  - Configuration 'releaseApiElements':
      - Found com.android.build.api.attributes.BuildTypeAttr 'release' but wasn't required.
      - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.
      - Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required.
      - Found org.gradle.api.attributes.Usage 'java-api' but wasn't required.
  - Configuration 'releaseRuntimeElements':
      - Found com.android.build.api.attributes.BuildTypeAttr 'release' but wasn't required.
      - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.
      - Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required.
      - Found org.gradle.api.attributes.Usage 'java-runtime' but wasn't required.

原因:

Android studio升级3.0导致apt失效

解决:

//第一步:project的build.gradle注释掉以下:
//classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'

//第二步:module的build.gradle注释掉以下:
//apply plugin: 'android-apt'

//第三步:module的build.gradle将apt修改为annotationProcessor,重新编译即可:
//apt 'com.jakewharton:butterknife-compiler:8.4.0'
//apt  rootProject.ext.dependencies["activityRouter-compiler"]
//apt  rootProject.ext.dependencies["ARouter-compiler"]
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
annotationProcessor  rootProject.ext.dependencies["activityRouter-compiler"]
annotationProcessor  rootProject.ext.dependencies["ARouter-compiler"]

This error message indicates that there is a conflict between different variants of the `org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0` dependency that your project is trying to use. The consumer was configured to find a runtime of a component compatible with Java 11, packaged as a jar, and its dependencies declared externally, but it cannot choose between the available variants of the dependency. To resolve this issue, you can try the following steps: - Check if your project is explicitly declaring a version of the `org.jetbrains.kotlin:kotlin-gradle-plugin` dependency that conflicts with the version required by the consumer (in this case, Java 11). If so, try updating the project to use the correct version of the dependency. - If the above step does not work, you can try adding a resolution strategy to your build script to force Gradle to choose the correct variant of the dependency. For example, you can add the following code to your `build.gradle` file: ``` configurations.all { resolutionStrategy { eachDependency { DependencyResolveDetails details -> if (details.requested.group == 'org.jetbrains.kotlin' && details.requested.name == 'kotlin-gradle-plugin' && details.requested.version == '1.7.0') { details.useVersion('1.7.0') } } } } ``` This code tells Gradle to use version `1.7.0` of the `org.jetbrains.kotlin:kotlin-gradle-plugin` dependency whenever it is required, regardless of any conflicting versions that may be present. If neither of these steps work, you may need to investigate further to find the root cause of the conflict.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值