当前位置:网站首页>Androd gradle's substitution of its use module dependency
Androd gradle's substitution of its use module dependency
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 .
The end of the
In the twinkling of an eye, time really flies . We go our separate ways , They also set out on their own journey , But even if I haven't seen you for years , Because of this friendship, we are still as before “ close ”. Don't forget the beginning of the party must always . Come on! , Programmers , in my opinion 35 year ,40 Age has never been a crisis , As long as you never forget why you set foot on the journey !
Finally, we need the same information , Sure I replied by private letter 【 Study 】 Or scan the QR code below I'd like to share it with you !
In order to let more friends who are studying or preparing for an interview recently see this article , I hope you can comment more , give the thumbs-up + forward !
** Thanks again to all my friends who have provided me with the topic , Thank you all the way !
边栏推荐
- [fh-gfsk] fh-gfsk signal analysis and blind demodulation research
- 2022 cable crane driver examination registration and cable crane driver certificate examination
- Niu Ke swipes questions and clocks in
- 【系统分析师之路】第五章 复盘软件工程(开发模型开发方法)
- [untitled]
- 攻克哈希的基本概念与实现
- ROS2之ESP32简单速度消息测试(极限频率)
- Key wizard play strange learning - multithreaded background coordinate recognition
- Excel if formula determines whether the two columns are the same
- Canvas drawing -- bingdd
猜你喜欢

matlab 多普勒效应产生振动信号和处理

Draw love with go+ to express love to her beloved

MySQL foundation 05 DML language

Excel removes the data after the decimal point and rounds the number

用Go+绘制爱心给心爱的她表白

2022.2.14 resumption

Top ten regular spot trading platforms 2022

Leetcode 6103 - minimum fraction to delete an edge from the tree

FPGA - 7系列 FPGA内部结构之Clocking -04- 多区域时钟

Database SQL language 01 where condition
随机推荐
Several cases of recursive processing organization
Usage of using clause in kingbases alter table
The difference between relational database and non relational database
Database SQL language 01 where condition
拥抱平台化交付的安全理念
tp6快速安装使用MongoDB实现增删改查
无向图的割点
MySQL
18_ The wechat video number of wechat applet scrolls and automatically plays the video effect to achieve 2.0
Niu Ke swipes questions and clocks in
2022.2.14 resumption
比较版本号
攻克哈希的基本概念与实现
Key wizard play strange learning - multithreaded background coordinate recognition
Basic concept and implementation of overcoming hash
MySQL
Button wizard play strange learning - automatic return to the city route judgment
MySQL --- 数据库查询 - 条件查询
Delete duplicate elements in the ordered linked list -ii
合并K个已排序的链表