暮雪(。・ω・。) 2024-03-14 10:12 采纳率: 75%
浏览 10
已结题

Android依赖冲突

img

Dependencies using groupId com.android.support and androidx.* can not be combined but found com.android.support:exifinterface:27.1.0 and androidx.appcompat:appcompat:1.6.1 incompatible dependencies

  • 写回答

4条回答 默认 最新

  • 檀越@新空间 2024-03-14 10:12
    关注

    暮雪(。・ω・。) 上午好☀️☀️☀️️
    本答案参考ChatGPT-3.5

    这个问题是由于在Android项目中,使用了 com.android.support 和 androidx.* 这两种不兼容的依赖关系导致的。具体来说,报错中显示了 com.android.support:exifinterface:27.1.0 和 androidx.appcompat:appcompat:1.6.1 这两个依赖之间有冲突。

    解决方案:

    1. 更新 com.android.support 依赖为 androidx.* 依赖:将项目中所有使用 com.android.support 依赖的地方,都改为对应的 androidx.* 依赖。比如,将 com.android.support:exifinterface:27.1.0 改为 androidx.exifinterface:exifinterface:1.1.0。

    2. 检查依赖冲突:使用 Gradle 的命令 gradlew -q dependencies 查看项目中所有的依赖关系,找出冲突的依赖并进行解决。

    3. 使用 dependencyResolutionRules:在项目的 build.gradle 文件中,使用 dependencyResolutionRules 属性来处理依赖冲突。具体步骤如下:

      • 在 build.gradle 文件的 android 节点下添加以下代码:
      configurations.all {
          resolutionStrategy {
              force "com.android.support:exifinterface:27.1.0"
              force "androidx.appcompat:appcompat:1.6.1"
          }
      }
      
      • 将强制使用指定版本的依赖,解决冲突问题。
    4. 排除冲突依赖:在项目的 build.gradle 文件中,使用 exclude 属性来排除冲突的依赖。具体步骤如下:

      • 在依赖声明中指定 exclude 块,排除冲突依赖的特定模块。例如:
      implementation('com.android.support:exifinterface:27.1.0') {
          exclude group: 'androidx.appcompat'
      }
      
      • 这样做将排除 com.android.support:exifinterface:27.1.0 中的 androidx.appcompat 模块,解决冲突问题。

    需要注意的是,解决依赖冲突可能还涉及到其他依赖关系,需要根据具体情况进行调整。在进行任何依赖更改之前,最好先备份项目或进行版本控制,以防万一。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

问题事件

  • 系统已结题 4月7日
  • 已采纳回答 3月30日
  • 创建了问题 3月14日