当前位置:网站首页>[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 》






边栏推荐
- 无向图的割点
- First hand evaluation of Reza electronics rz/g2l development board
- ROS2之ESP32简单速度消息测试(极限频率)
- (C语言)数据的存储
- 465. DFS backtracking of optimal bill balance
- d,ldc構建共享庫
- Canvas drawing -- bingdd
- MySQL
- 信息熵的基础
- [flutter] icons component (load the built-in icon of flutter | display the material design icon completely)
猜你喜欢

Draw love with go+ to express love to her beloved

机器学习术语

Explain the basic concepts and five attributes of RDD in detail

leetcode:701. 二叉搜索树中的插入操作【bst的插入】

JS inheritance and prototype chain

First hand evaluation of Reza electronics rz/g2l development board
![leetcode:701. Insertion in binary search tree [BST insertion]](/img/bc/1dda73198488eb81b49be2c1dff6c2.png)
leetcode:701. Insertion in binary search tree [BST insertion]
![[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)

Androd Gradle 对其使用模块依赖的替换

MySQL basic usage 02
随机推荐
dotConnect for PostgreSQL数据提供程序
On Fibonacci sequence
The industrial scope of industrial Internet is large enough. The era of consumer Internet is only a limited existence in the Internet industry
Asynchronous, email and scheduled tasks
合并K个已排序的链表
MySQL foundation 07-dcl
对非ts/js文件模块进行类型扩充
1038 Recover the Smallest Number
MySQL基础用法02
[FPGA tutorial case 5] ROM design and Implementation Based on vivado core
2022.2.14 resumption
有向图的强连通分量
安全运营四要素之资产、脆弱性、威胁和事件
Key wizard play strange learning - front desk and Intranet send background verification code
The difference between relational database and non relational database
Excel calculates the difference between time and date and converts it into minutes
R language generalized linear model function GLM, (model fit and expression diagnostics), model adequacy evaluation method, use plot function and car package function
【FH-GFSK】FH-GFSK信号分析与盲解调研究
[flutter] icons component (load the built-in icon of flutter | display the material design icon completely)
Button wizard play strange learning - go back to the city to buy medicine and add blood