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`命令可以查看依赖冲突的详细信息。

相关推荐
有位神秘人20 小时前
Android中获取设备里面的音频文件
android
2501_9159184121 小时前
使用 HBuilder 上架 iOS 应用时常见的问题与应对方式
android·ios·小程序·https·uni-app·iphone·webview
farewell-Calm21 小时前
01_Android快速入门
android
helloCat1 天前
记录CI/CD自动化上传AppGallery遇到的坑
android·前端·api
WordPress学习笔记1 天前
wordpress根据页面别名获取该页面的链接
android·wordpress
2501_916007471 天前
iOS 崩溃日志的分析方法,将崩溃日志与运行过程结合分析
android·ios·小程序·https·uni-app·iphone·webview
浅箬1 天前
Taro3的H5项目在Android、IOS 中因为兼容性问题导致的白屏问题
android·团队开发·taro
技术摆渡人1 天前
Android 全栈架构终极指南:从 Linux 内核、Binder 驱动到 Framework 源码实战
android·linux·架构
00后程序员张1 天前
苹果应用商店上架App流程,签名证书、IPA 校验、上传
android·ios·小程序·https·uni-app·iphone·webview
2501_916007471 天前
iOS 上架需要哪些准备,围绕证书、描述文件和上传方式等关键环节展开分析
android·ios·小程序·https·uni-app·iphone·webview