• 支持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”

const val material = “com.google.android.material:material:1.2.1”

const val junittest = “androidx.test.ext:junit:1.1.2”

const val swiperefreshlayout = “androidx.swiperefreshlayout:swiperefreshlayout:1.1.0”

const val recyclerview = “androidx.recyclerview:recyclerview:1.1.0”

const val cardview = “androidx.cardview:cardview:1.0.0”

//Depend

const val junit = “junit:junit:4.12”

const val espresso_core = “com.android.support.test.espresso:espresso-core:3.0.2”

const val guava = “com.google.guava:guava:24.1-jre”

const val commons = “org.apache.commons:commons-lang3:3.6”

const val zxing = “com.google.zxing:core:3.3.2”

//leakcanary

const val leakcanary = “com.squareup.leakcanary:leakcanary-android:2.4”

//jetPack

const val room_runtime = “androidx.room:room-runtime:2.2.5”

const val room_compiler = “androidx.room:room-compiler:2.2.5”

const val room_rxjava2 = “androidx.room:room-rxjava2:2.2.5”

const val lifecycle_extensions = “android.arch.lifecycle:extensions:1.1.1”

const val lifecycle_compiler = “android.arch.lifecycle:compiler:1.1.1”

const val rxlifecycle = “com.trello.rxlifecycle3:rxlifecycle:3.1.0”

const val rxlifecycle_components = “com.trello.rxlifecycle3:rxlifecycle-components:3.1.0”

//Kotlin

const val kotlinx_coroutines_core = “org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.7”

}

4.在 VersionPlugin/src/main/java/包名/ 目录下新建 VersionPlugin.kt,

实现Plugin接口,如下:

package com.controler.versionplugin

import org.gradle.api.Plugin

import org.gradle.api.Project

class VersionPlugin : Plugin{

override fun apply(p0: Project) {

}

companion object{

}

}

注:新建VersionPlugin module时,生成的其他无用资源可以删去,只保留需要的,如下:

5.在 settings.gradle 文件内添加 includeBuild ("VersionPlugin")',注意是includeBuild 哦~,Rebuild项目

6.后面就可以在需要使用的gradle文件中使用了,如
app下的build.gradle,在首行添加以下内容:

plugins {

// 在第二部定义的插件ID

id “com.controler.versionplugin”

}

// 定义的依赖地址

import com.controler.versionplugin.*

使用如下


r.versionplugin"

}

// 定义的依赖地址

import com.controler.versionplugin.*

使用如下

Android Studio统一依赖管理Composing builds,2021最新网易Android面经相关推荐

  1. Android Studio统一依赖管理Composing builds

    glideVersion : "4.11.0", okhttpVersion : "3.11.0", retrofitVersion : "2.3.0 ...

  2. 统一依赖管理Composing builds

    背景 在我们的AS项目中,经常引用多个Module,多人参与项目开发,这种背景下,我们会时常遇到版本冲突问题,出现不同的compileSdkVersion等,导致我们的包体变大,项目运行时间变长,所以 ...

  3. 【gradle Composing builds】gradle依赖管理Composing builds之杂症-快速同步

    Composing builds杂症-快速同步 问题描述 作为一个有强迫症的人,在使用Composing builds后一直耿耿于怀,第一次打开项目后,Ctrl+左键点击定义的依赖不能跳转,build ...

  4. Android Studio使用Composing builds统一依赖管理

    Composing builds 一.啥是 Composing builds ?? https://docs.gradle.org/current/userguide/composite_builds ...

  5. Android gradle统一依赖版本:Composing builds

    之前写过一篇Android gradle统一依赖版本:kotlin+buildSrc的集成使用, 两者的区别可以参照再见吧 buildSrc, 拥抱 Composing builds 提升 Andro ...

  6. AndroidStudio使用进阶二:搭建自己的maven私服,并使用Gradle统一依赖管理

    前言: 最近我们老大组织了我们软件团队开了一个小会,说了一些存在的问题,平时在技术上的交流还是比较少的,尤其是在不同的项目之间的开发人员,然而经过这次会议我突然发现,我的缺陷不仅是在基础的能力上,还有 ...

  7. Android Studio安装及SDK下载安装2021

    Android开发:Android Studio安装及SDK下载安装2021 首先确保系统已经安装jdk 1.8版本以上.如果不确定自己安装的版本可以这样查看:首先win+r输入cmd进入这样的页面: ...

  8. Android Studio support 26.0.0-alpha1 Failed to resolve: com.android.support:appcompat-v7:27.+ 报错解决方法

    Android Studio support 26.0.0-alpha1 Failed to resolve: com.android.support:appcompat-v7:27.+ 报错解决方法 ...

  9. Android studio运行出现Unable to determine application id: com.android.tools.idea.run.ApkProvisionExcepti

    Android studio运行出现Unable to determine application id: com.android.tools.idea.run.ApkProvisionExcepti ...

最新文章

  1. ubuntu安装mysql可视化工具MySQL-workbench及简单操作
  2. 基于HAproxy的web动静分离及输出状态检测页面
  3. androidsettitle方法_在Android应用程序中,Toolbar.setTitle方法无效-应用程序名称显示为标题...
  4. Oracle Study之--Oracle 11g RAC设置归档路径错误案例
  5. 图解Javascript——作用域、作用域链、闭包
  6. 小米电视双十一大降价:55寸仅1399元
  7. 【Elasticsearch】实施现代电子商务搜索
  8. 在SQL Server中通过PowerUpSQL获得Windows自动登录密码
  9. Teradata中的四舍五入问题
  10. java实现与图灵机器人聊天_调用图灵机器人API实现简单聊天
  11. su必备插件_sketchup插件 su十大必备插件
  12. Epsilon-Greedy算法
  13. html统计表合并单元格的快捷键,excel中合并单元格的快捷键的方法及设置技巧
  14. 5G消息来了,它会干掉微信还是变成另一个飞信?
  15. 你的设备遇到问题,需要重启;我们只收集某些错误信息,然后为你重新启动。
  16. python在大数据分析中的应用
  17. pytorch 支持amd显卡吗_2020-06-12 ubuntu系统下,pytorch安装
  18. mipi传输距离3米_弱电网络工程中网线大于100米怎么办?离300米远用什么线缆较好?...
  19. Gitee生成公钥详细教程
  20. 将字符串,数组等任意格式转为json(JSON)数据,Arrays是数组工具类,将任意数组转字符串或数组操作

热门文章

  1. 机器学习6-强化学习
  2. windows之wps卸载不干净解决
  3. 拉斯维加斯类型概率算法-n皇后问题
  4. java边缘检测算子代码_图像边缘检测(Canny 算法)的Java实现
  5. 成都学编程哪个学校好
  6. 测试面试题 - GIT
  7. vue项目实现打印预览、生成(导出)文档功能
  8. linux 内核源码下载
  9. 计算机数值分析-插值法-差商-04
  10. Linux一键实现ramos打造自己的livecd