为什么你的gradle还在can not resolve???

2020-09-29  本文已影响0人  雅卅夕

gradle如何下载sdk

gradle开始构建之前,会先确定需要参与构建的sdk以及他们的版本,并且下载到本地(当然也有可能使用缓存,本文不讨论这种情况),gradle的这个操作简单来说分为两个步骤:

1.确定sdk的版本号

2.下载sdk

如何优化

不知道项目中哪个sdk的版本号是动态的?在项目的根目录运行下面的命令:

./gradlew app:dependencies > depts.txt

这个命令生成项目的依赖树并保存在depts.txt文件中,在依赖树中可以看到哪些sdk的版本号是动态的:

[图片上传失败...(image-56f6ba-1601375116238)]

这里动态依赖已经被固定为一个精确的版本了。如何固定版本?在app/build.gradle中配置,与android的配置同级

configurations.all { Configuration configuration ->
    configuration.resolutionStrategy { ResolutionStrategy resolutionStrategy ->
        resolutionStrategy.force "com.amap.api:location:5.1.0"
        resolutionStrategy.force "com.amap.api:map2d:6.0.0"
        resolutionStrategy.force "com.amap.api:search:7.4.0"
    }
}

额外扩展

<img src="//p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/23140db7c4cf4eb188b3360ad9269974~tplv-k3u1fbpfcp-zoom-1.image" alt="image-20200929165346087" style="zoom:70%;" />

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>androidx.constraintlayout</groupId>
  <artifactId>constraintlayout</artifactId>
  <version>2.0.1</version>
  <packaging>aar</packaging>
  <name>Android ConstraintLayout</name>
  <description>ConstraintLayout for Android</description>
  <url>http://tools.android.com</url>
  <inceptionYear>2007</inceptionYear>
  <licenses>
    <license>
      <name>The Apache Software License, Version 2.0</name>
      <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
      <distribution>repo</distribution>
    </license>
  </licenses>
  <developers>
    <developer>
      <name>The Android Open Source Project</name>
    </developer>
  </developers>
  <scm>
    <connection>git://android.googlesource.com/platform/tools/sherpa.git</connection>
    <url>https://android.googlesource.com/platform/tools/sherpa</url>
  </scm>
  <dependencies>
    <dependency>
      <groupId>androidx.appcompat</groupId>
      <artifactId>appcompat</artifactId>
      <version>1.2.0</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>androidx.core</groupId>
      <artifactId>core</artifactId>
      <version>1.3.1</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>androidx.constraintlayout</groupId>
      <artifactId>constraintlayout-solver</artifactId>
      <version>2.0.1</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>
</project>

> 使用exclude排除掉constraintlayout中依赖的appcompat
>
> ```groovy
> implementation("androidx.constraintlayout:constraintlayout:2.0.1") {
>         exclude group: 'androidx.appcompat', module: 'appcompat'
>     }
> ```

参考文档:

上一篇下一篇

猜你喜欢

热点阅读