当前位置:网站首页>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 !
边栏推荐
- 465. DFS backtracking of optimal bill balance
- MySQL foundation 07-dcl
- Kivy tutorial - example of using Matplotlib in Kivy app
- R language uses coin package to apply permutation tests to independence problems (permutation tests, whether response variables are independent of groups, are two numerical variables independent, and
- [Androd] Gradle 使用技巧之模块依赖替换
- 【FPGA教程案例6】基于vivado核的双口RAM设计与实现
- Linear programming of mathematical modeling (including Matlab code)
- 18_微信小程序之微信视频号滚动自动播放视频效果实现2.0
- 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
- Niu Ke swipes questions and clocks in
猜你喜欢

Strongly connected components of digraph
![[shutter] image component (configure local GIF image resources | load placeholder with local resources)](/img/73/19e2e0fc5ea6f05e34584ba40a452d.jpg)
[shutter] image component (configure local GIF image resources | load placeholder with local resources)

dotConnect for PostgreSQL数据提供程序
![leetcode:701. Insertion in binary search tree [BST insertion]](/img/bc/1dda73198488eb81b49be2c1dff6c2.png)
leetcode:701. Insertion in binary search tree [BST insertion]

1696C. Fishingprince Plays With Array【思维题 + 中间状态 + 优化存储】

Esp32 simple speed message test of ros2 (limit frequency)

(C语言)数据的存储

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

MySQL

MySQL basic usage 02
随机推荐
2022 Jiangxi Provincial Safety Officer B certificate reexamination examination and Jiangxi Provincial Safety Officer B certificate simulation examination question bank
leetcode:871. Minimum refueling times [Pat has done before + maximum stacking + greed]
电话网络问题
18_微信小程序之微信视频号滚动自动播放视频效果实现2.0
First hand evaluation of Reza electronics rz/g2l development board
MySQL
leetcode:701. Insertion in binary search tree [BST insertion]
1038 Recover the Smallest Number
Find a benchmark comrade in arms | a million level real-time data platform, which can be used for free for life
Strongly connected components of digraph
[fh-gfsk] fh-gfsk signal analysis and blind demodulation research
leetcode 2097 — 合法重新排列数对
【FPGA教程案例6】基于vivado核的双口RAM设计与实现
【FPGA教程案例5】基于vivado核的ROM设计与实现
用Go+绘制爱心给心爱的她表白
Specified interval inversion in the linked list
Now that the teenager has returned, the world's fireworks are the most soothing and ordinary people return to work~
2022 Jiangxi Provincial Safety Officer B certificate reexamination examination and Jiangxi Provincial Safety Officer B certificate simulation examination question bank
【C语言】分支和循环语句(上)
2022.2.14 resumption