Android Studio统一依赖管理Composing builds
glideVersion : “4.11.0”,
okhttpVersion : “3.11.0”,
retrofitVersion : “2.3.0”,
constraintLayoutVersion: “1.1.3”,
gsonVersion : “2.7”,
rxjavaVersion : “2.2.2”,
rxandroidVersion : “2.1.0”,
…省略…
]
dependencies = [
//base
“constraintLayout” : “androidx.constraintlayout:constraintlayout:${version[“constraintLayoutVersion”]}”,
“appcompat” : “androidx.appcompat:appcompat:${version[“appcompatVersion”]}”,
“coreKtx” : “androidx.core:core-ktx:${version[“coreKtxVersion”]}”,
“material” : “com.google.android.material:material:1.2.1”,
//multidex
“multidex” : “com.android.support:multidex:${version[“multidexVersion”]}”,
//okhttp
“okhttp” : “com.squareup.okhttp3:okhttp:${version[“okhttpVersion”]}”,
“logging-interceptor” : “com.squareup.okhttp3:logging-interceptor:${version[“okhttpVersion”]}”,
//retrofit
“retrofit” : “com.squareup.retrofit2:retrofit:${version[“retrofitVersion”]}”,
“converter-gson” : “com.squareup.retrofit2:converter-gson:${version[“retrofitVersion”]}”,
“adapter-rxjava2” : “com.squareup.retrofit2:adapter-rxjava2:${version[“retrofitVersion”]}”,
“converter-scalars” : “com.squareup.retrofit2:converter-scalars:${version[“retrofitVersion”]}”,
…省略…
]
}
依赖写完之后,在root路径下的build.gradle
添加apply from: "config.gradle"
然后在需要依赖的module下的build.gradle中
dependencies {
…
// Retrofit + okhttp 相关的依赖包
api rootProject.ext.dependencies[“retrofit”]
…
}
以上就是Groovy ext扩展函数的依赖管理方式,此方式可以做到版本依赖,但是最大的缺点就是无法跟踪代码,想要找到上面示例代码中的rootProject.ext.dependencies["retrofit"]
这个依赖,需要手动切到config.gradle去搜索查找,可读性很差。
[](()二、使用buildSrc+kotlin的方式
buildSrc的方式,是最近几年特别流行的版本依赖管理方式。它有以下几个优点:
支持双向跟踪
buildSrc是Android默认插件,全局只有这一个地方可以修改
支持Android Studio的代码补全,以下演示示例图来自于网络
使用方式可参考:[Kotlin + buildSrc for Better Gradle Dependency Management](()
缺点:buildSrc 依赖更新将重新构建整个项目,项目越大,重新构建的时间就越长,造成不必要的时间浪费。
[](()三、Composing builds
[Composing builds](():A composite build is simply a build that includes other builds. In many ways a composite build is similar to a Gradle multi-project build, except that instead of including single projects, complete builds are included.(Composing builds只是包含其他构建的构建。 在许多方面,复合构建类似于Gradle多项目构建,不同之处在于,它包括完整的构建,而不是包括单个项目。)
使用这种方式的优点有:
1.支持单向跟踪
2.自动补全
3.依赖更新时,不会重新构建整个项目
使用方式
1.新建module,名为VersionPlugin(自起)
2.在新建的module下的build.gradle文件中,添加如下代码:
buildscript {
repositories {
jcenter()
}
dependencies {
// 因为使用的 Kotlin 需要需要添加 Kotlin 插件
classpath “org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.10”
}
}
apply plugin: ‘kotlin’
apply plugin: ‘java-gradle-plugin’
repositories {
// 需要添加 jcenter 否则会提示找不到 gradlePlugin
jcenter()
google()
}
dependencies {
implementation gradleApi()
implementation “org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.10”
}
compileKotlin {
kotlinOptions {
jvmTarget = “1.8”
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = “1.8”
}
}
gradlePlugin {
plugins {
version {
// 在 app 模块需要通过 id 引用这个插件
id = ‘com.controler.versionplugin’
// 实现这个插件的类的路径
implementationClass = ‘com.controler.versionplugin.VersionPlugin’
}
}
}
3.在 VersionPlugin/src/main/java/包名/
目录下新建 DependencyManager.kt 文件,添加你的依赖配置,如:
package com.controler.versionplugin
/**
- 配置和 build相关的
*/
object BuildVersion {
const val compileSdkVersion = 29
const val buildToolsVersion = “29.0.2”
const val minSdkVersion = 17
const val targetSdkVersion = 26
const val versionCode = 102
const val versionName = “1.0.2”
}
/**
- 项目相关配置
*/
object BuildConfig {
//AndroidX
const val appcompat = “androidx.appcompat:appcompat:1.2.0”
const val constraintLayout = “androidx.constraintlayout:constraintlayout:2.0.4”
const val coreKtx = “androidx.core:core-ktx:1.3.2”
Android Studio统一依赖管理Composing builds相关推荐
- Android Studio统一依赖管理Composing builds,2021最新网易Android面经
支持Android Studio的代码补全,以下演示示例图来自于网络 使用方式可参考:Kotlin + buildSrc for Better Gradle Dependency Management ...
- 统一依赖管理Composing builds
背景 在我们的AS项目中,经常引用多个Module,多人参与项目开发,这种背景下,我们会时常遇到版本冲突问题,出现不同的compileSdkVersion等,导致我们的包体变大,项目运行时间变长,所以 ...
- 【gradle Composing builds】gradle依赖管理Composing builds之杂症-快速同步
Composing builds杂症-快速同步 问题描述 作为一个有强迫症的人,在使用Composing builds后一直耿耿于怀,第一次打开项目后,Ctrl+左键点击定义的依赖不能跳转,build ...
- Android Studio使用Composing builds统一依赖管理
Composing builds 一.啥是 Composing builds ?? https://docs.gradle.org/current/userguide/composite_builds ...
- Android gradle统一依赖版本:Composing builds
之前写过一篇Android gradle统一依赖版本:kotlin+buildSrc的集成使用, 两者的区别可以参照再见吧 buildSrc, 拥抱 Composing builds 提升 Andro ...
- AndroidStudio使用进阶二:搭建自己的maven私服,并使用Gradle统一依赖管理
前言: 最近我们老大组织了我们软件团队开了一个小会,说了一些存在的问题,平时在技术上的交流还是比较少的,尤其是在不同的项目之间的开发人员,然而经过这次会议我突然发现,我的缺陷不仅是在基础的能力上,还有 ...
- android compile使用方法,自己创建一个android studio在线依赖compile
相信大家在使用AS(android studio)的时候添加依赖的时候有没见过如下方式: 很酷炫本人将教你如何做到. 1. 使用 jcenter()实现- 在创建的时候as自动帮我导入了 1. ...
- android jar包 下载地址,Android Studio项目依赖包下载到本地的jar或aar的路径
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/chenzhengfeng/articl ...
- Android Studio下载依赖慢,使用国内阿里云镜像搞定
首先百度 "Android Studio 依赖国内镜像" 好些文章都是在介绍这个方式,我试验了一下,行不通,所以代理这种就放弃了. 后来找到了这篇文章Android Studio配 ...
最新文章
- 技术图文:进一步完善自动化交易系统 - 01
- 几道 BAT 算法面试中经常问的「字符串」问题
- 化工热力学:第三章 纯流体的热力学性质
- 阿里云成为首个通过《面向公有云模式的政务云服务》测评的厂商
- whether logo retrieval will block the application
- pythonweb面试常见问题_python和web框架面试题目整理(3)
- 为什么有些人看了别人的总结、经验、教训,依然没有用。
- Android 打aar包
- 永不失联?iPhone 13或将支持低轨道卫星通讯
- OpenCV入门教程
- 微信小程序——云开发入门
- 关于CIE RGB色坐标图转换到CIE XYZ色坐标图
- 米家和苹果HomeKit二选一,你怎么选?
- 线程的先进先出,后进先出,以及优先级队列
- 笔记本卡顿不流畅是什么原因_电脑卡顿不流畅是什么原因?
- 计算机桌面背景显示方式有几种,如何让计算机自动更改桌面背景
- GIT提交代码到远程创库
- 初学C语言1--C语言用什么软件编写
- 目标检测YOLO实战应用案例100讲-基于多尺度特征融合的水下小目标检测方法研究
- [无线玩家]玩转无线路由之DD-WRT基础扫盲
热门文章
- 更新域内计算机时间,Word2013如何自动更新文档中的日期和时间?如何设置打印前自动更新域...
- ARM开发板如何安装Linux系统
- mysql建库、建表命令、sql语句大全
- 信息熵:什么是信息熵?
- ios之实现自动无限循环滚动视图(1)
- 读书笔记 -公司改造 和 紧迫感
- ArrayList和LinkedList的区别以及优缺点
- Hander异步消息处理机制完全解析
- matlab 矩阵平均值
- 计算机考研专硕好考还是学硕好考,考研是学硕难考还是专硕难考?很多人都猜错了...