当前位置:网站首页>[androd] module dependency replacement of gradle's usage skills
[androd] module dependency replacement of gradle's usage skills
2022-07-03 01:19:00 【Xiao Chen knocked the code randomly】
background
We are in the process of multi module project development , There are scenes like this , The project relies on one's own or other colleagues aar modular , Sometimes for the convenience of development and debugging , Often put aar Change to local source code dependency , When the development is completed and submitted , It will be modified back to aar rely on , This will be very inconvenient , The development process is shown below :

solve
At first we passed in app Of build.gradle Inside dependency Judge if it needs local dependency aar, Just replace it with implementation project rely on , The pseudocode is as follows :
dependencies {
if(enableLocalModule) {
implementation 'custom:test:0.0.1'
} else {
implementation project(path: ':test')
}
}
This way, you don't have to modify the code back every time you submit it aar rely on , But if other modules also rely on this aar modular , There will be problems , Although you can continue to modify the dependencies in other modules , But it's invasive , And it can't completely solve the problem , Local dependencies and aar Dependent code inconsistencies .
Gradle Officials offer a better solution to this scenario DependencySubstitution, Use as follows :
step 1: stay settting.gradle, Add the following code :
// Load local module
if (file("local.properties").exists()) {
def properties = new Properties()
def inputStream = file("local.properties").newDataInputStream()
properties.load( inputStream )
def moduleName = properties.getProperty("moduleName")
def modulePath = properties.getProperty("modulePath")
if (moduleName != null && modulePath != null) {
include moduleName
project(moduleName).projectDir = file(modulePath)
}
}
step 2: stay app Of build.gradle Add the following code
configurations.all {
resolutionStrategy.dependencySubstitution.all { DependencySubstitution dependency ->
// use local module
if (dependency.requested instanceof ModuleComponentSelector && dependency.requested.group == "custom") {
def targetProject = findProject(":test")
if (targetProject != null) {
dependency.useTarget targetProject
}
}
}
}
step 3:: stay local.properties in
moduleName=:test
modulePath=../AndroidStudioProjects/TestProject/testModule
It's done here , The follow-up only needs to be in local.properties Opening and closing , That is to say aar Module local dependency debugging , You don't have to modify the code manually aar rely on .
Last
Give you a complete set of Android Study materials .
I used to find it on the Internet , The things found are scattered , Most of the time, I just look at it and it's gone , Time is wasted , The problem has not been solved yet , It's crazy .
Then I sorted out a set of materials myself , Also don't say , It's delicious !
The information is organized , There is a system , It's also comprehensive , It's not convenient for me to release it directly , You can first see if there is anything you can use .
** Attach white whoring address :《Android Architecture video +BATJ Interview topics PDF+ Learning notes 》






边栏推荐
- 异步、邮件、定时三大任务
- 产业互联网的产业范畴足够大 消费互联网时代仅是一个局限在互联网行业的存在
- 12_ Implementation of rolling automatic video playback effect of wechat video number of wechat applet
- Compare version number
- Matlab saves the digital matrix as geospatial data, and the display subscript index must be of positive integer type or logical type. Solve the problem
- tp6快速安装使用MongoDB实现增删改查
- Key wizard hit strange learning - automatic path finding back to hit strange points
- Foundations of data science is free to download
- [C language] branch and loop statements (Part 1)
- 软考信息系统项目管理师_历年真题_2019下半年错题集_上午综合知识题---软考高级之信息系统项目管理师053
猜你喜欢
![[flutter] icons component (load the built-in icon of flutter | display the material design icon completely)](/img/f5/3ec22f1480227f33a1c8ac457155ed.jpg)
[flutter] icons component (load the built-in icon of flutter | display the material design icon completely)

Merge K sorted linked lists

Niu Ke swipes questions and clocks in
![[fh-gfsk] fh-gfsk signal analysis and blind demodulation research](/img/8a/8ca80f51a03341c982d52980c54b01.png)
[fh-gfsk] fh-gfsk signal analysis and blind demodulation research

Daily topic: movement of haystack

Database SQL language 01 where condition

【我的OpenGL学习进阶之旅】关于欧拉角、旋转顺序、旋转矩阵、四元数等知识的整理

正确甄别API、REST API、RESTful API和Web Service之间的异同

寻找标杆战友 | 百万级实时数据平台,终身免费使用

MySQL基础用法02
随机推荐
Makefile中wildcard、patsubst、notdir的含义
Mongodb common commands of mongodb series
鏈錶內指定區間反轉
Now that the teenager has returned, the world's fireworks are the most soothing and ordinary people return to work~
Key wizard hit strange learning - automatic path finding back to hit strange points
【FH-GFSK】FH-GFSK信号分析与盲解调研究
Machine learning terminology
kivy教程之在 Kivy App 中使用 matplotlib 的示例
FPGA - 7系列 FPGA内部结构之Clocking -04- 多区域时钟
安全运营四要素之资产、脆弱性、威胁和事件
【我的OpenGL学习进阶之旅】关于欧拉角、旋转顺序、旋转矩阵、四元数等知识的整理
Top ten regular spot trading platforms 2022
Delete duplicate elements in the ordered linked list -ii
R language ggplot2 visualization: use ggplot2 to display dataframe data that are all classified variables in the form of thermal diagram, and customize the legend color legend of factor
[day 29] given an integer, please find its factor number
Inversion de l'intervalle spécifié dans la liste des liens
12_ Implementation of rolling automatic video playback effect of wechat video number of wechat applet
软考信息系统项目管理师_历年真题_2019下半年错题集_上午综合知识题---软考高级之信息系统项目管理师053
First hand evaluation of Reza electronics rz/g2l development board
Detailed explanation of Q-learning examples of reinforcement learning