当前位置:网站首页>[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 》
边栏推荐
- Appuyez sur l'apprentissage de l'esprit de frappe - reconnaissance des coordonnées de fond multithreadées
- 强化学习 Q-learning 实例详解
- Explain the basic concepts and five attributes of RDD in detail
- 有向图的强连通分量
- 【C语言】指针与数组笔试题详解
- On Fibonacci sequence
- Machine learning terminology
- Top ten regular spot trading platforms 2022
- Linear programming of mathematical modeling (including Matlab code)
- [self management] time, energy and habit management
猜你喜欢
dotConnect for PostgreSQL数据提供程序
leetcode 2097 — 合法重新排列数对
正确甄别API、REST API、RESTful API和Web Service之间的异同
excel IF公式判断两列是否相同
matlab 多普勒效应产生振动信号和处理
异步、郵件、定時三大任務
Daily topic: movement of haystack
1696C. Fishingprince plays with array [thinking questions + intermediate state + optimized storage]
拥抱平台化交付的安全理念
[fh-gfsk] fh-gfsk signal analysis and blind demodulation research
随机推荐
链表内指定区间反转
matlab查找某一行或者某一列在矩阵中的位置
Top ten regular spot trading platforms 2022
强化学习 Q-learning 实例详解
[flutter] icons component (fluttericon Download Icon | customize SVG icon to generate TTF font file | use the downloaded TTF icon file)
The R language uses the ctree function in the party package to build conditional inference decision trees, uses the plot function to visualize the trained conditional inference decision tree, and the
leetcode 2097 — 合法重新排列数对
leetcode:701. 二叉搜索树中的插入操作【bst的插入】
Asynchronous, email and scheduled tasks
Basic concept and implementation of overcoming hash
1038 Recover the Smallest Number
Canvas drawing -- bingdd
拥抱平台化交付的安全理念
Arduino DY-SV17F自动语音播报
Matlab finds the position of a row or column in the matrix
MySQL foundation 05 DML language
【我的OpenGL学习进阶之旅】关于欧拉角、旋转顺序、旋转矩阵、四元数等知识的整理
leetcode 6103 — 从树中删除边的最小分数
What is needed to develop a domestic arm intelligent edge computing gateway
电话网络问题