Android 解决Gradle 三方依赖冲突方法

一、查找冲突的包

./gradlew app:dependencies

二、解决方案

第一种:

排除依赖中的指定包

exclude group:表示只要包含com.github.piasy 的都排除

compile ('com.mcxiaoke.viewpagerindicator:library:2.4.1') {

exclude group: 'com.android.support'

exclude group: 'com.android.support', module: 'support-v13'

}

第二种:

force强制设置某个模块的版本

configurations.all {

resolutionStrategy {

force 'com.android.support:support-v4:24.1.0'

}

第三种:

force强制设置整个工程的的版本 在根目录的gradle.build文件中设置

allprojects {

configurations.all {

resolutionStrategy.eachDependency { DependencyResolveDetails details ->

def requested = details.requested

if (requested.group == 'com.android.support') {

if (requested.name.startsWith("support-fragment")) {

details.useVersion '28.0.0'

}

}

}

}

}

第四种

  1. 使用`maven-enforcer-plugin`插件强制执行依赖规则:在build.gradle文件中,可以使用`maven-enforcer-plugin`插件来强制执行依赖规则。例如:

plugins {

id 'maven-enforcer-plugin' version

}

查找依赖冲突

使用`dependencyUpdates`插件查找依赖冲突:在build.gradle文件中,可以使用`dependencyUpdates`插件来查找依赖冲突。例如:

```

plugins {

id 'com.github.ben-manes.versions' version '0.36.0'

}

task dependencyUpdates(type: DependencyUpdatesTask) {

outputFormatter = 'json'

}

上面的代码中,我们使用了`dependencyUpdates`插件,并定义了一个`dependencyUpdates`任务来查找依赖冲突。执行`./gradlew dependencyUpdates`命令可以查看依赖冲突的详细信息。

相关推荐
深海呐4 小时前
Android AlertDialog圆角背景不生效的问题
android
ljl_jiaLiang4 小时前
android10 系统定制:增加应用使用数据埋点,应用使用时长统计
android·系统定制
花花鱼4 小时前
android 删除系统原有的debug.keystore,系统运行的时候,重新生成新的debug.keystore,来完成App的运行。
android
落落落sss5 小时前
sharding-jdbc分库分表
android·java·开发语言·数据库·servlet·oracle
消失的旧时光-19437 小时前
kotlin的密封类
android·开发语言·kotlin
服装学院的IT男9 小时前
【Android 13源码分析】WindowContainer窗口层级-4-Layer树
android
CCTV果冻爽10 小时前
Android 源码集成可卸载 APP
android
码农明明10 小时前
Android源码分析:从源头分析View事件的传递
android·操作系统·源码阅读
秋月霜风11 小时前
mariadb主从配置步骤
android·adb·mariadb
Python私教12 小时前
Python ORM 框架 SQLModel 快速入门教程
android·java·python