当前位置:网站首页>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 !
边栏推荐
- Linear programming of mathematical modeling (including Matlab code)
- excel IF公式判断两列是否相同
- 机器学习术语
- Compare version number
- Assets, vulnerabilities, threats and events of the four elements of safe operation
- Top ten regular spot trading platforms 2022
- 465. 最优账单平衡 DFS 回溯
- leetcode:871. 最低加油次数【以前pat做过 + 最大堆 +贪心】
- Delete duplicate elements in the ordered linked list -ii
- 【FH-GFSK】FH-GFSK信号分析与盲解调研究
猜你喜欢
每日一题之干草堆的移动
1696C. Fishingprince plays with array [thinking questions + intermediate state + optimized storage]
leetcode 2097 — 合法重新排列数对
拥抱平台化交付的安全理念
[fh-gfsk] fh-gfsk signal analysis and blind demodulation research
excel IF公式判断两列是否相同
电话网络问题
信息熵的基础
JDBC courses
leetcode:871. Minimum refueling times [Pat has done before + maximum stacking + greed]
随机推荐
2022 Jiangxi Provincial Safety Officer B certificate reexamination examination and Jiangxi Provincial Safety Officer B certificate simulation examination question bank
Understanding and distinguishing of some noun concepts in adjustment / filtering
【C语言】指针与数组笔试题详解
Telephone network problems
12_ Implementation of rolling automatic video playback effect of wechat video number of wechat applet
First hand evaluation of Reza electronics rz/g2l development board
18_ The wechat video number of wechat applet scrolls and automatically plays the video effect to achieve 2.0
[Arduino experiment 17 L298N motor drive module]
d,ldc构建共享库
MySQL
JS inheritance and prototype chain
Kivy tutorial - example of using Matplotlib in Kivy app
Usage of using clause in kingbases alter table
按键精灵打怪学习-前台和内网发送后台验证码
基本远程连接工具Xshell
如今少年已归来,人间烟火气最抚凡人心 复工了~
leetcode:871. Minimum refueling times [Pat has done before + maximum stacking + greed]
Matlab Doppler effect produces vibration signal and processing
每日一题之干草堆的移动
比较版本号