当前位置:网站首页>Androd Gradle模块依赖替换如何使用
Androd Gradle模块依赖替换如何使用
2022-06-23 12:53:00 【亿速云】
Androd Gradle模块依赖替换如何使用
本篇内容介绍了“Androd Gradle模块依赖替换如何使用”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
背景
我们在多模块项目开发过程中,会遇到这样的场景,工程里依赖了一个自己的或者其他同事的 aar 模块,有时候为了开发调试方便,经常会把 aar 改为本地源码依赖,开发完毕并提交的时候,会再修改回 aar 依赖,这样就会很不方便,开发流程图示如下:

解决
一开始我们通过在 app 的 build.gradle 里的 dependency 判断如果是需要本地依赖的 aar,就替换为 implementation project 依赖,伪代码如下:
dependencies { if(enableLocalModule) { implementation 'custom:test:0.0.1' } else { implementation project(path: ':test') }}这样就可以不用每次提交代码还要修改回 aar 依赖,但是如果其他模块如果也依赖了该 aar 模块,就会出现问题,虽然可以继续修改其他模块里的依赖方式,但是这样就会有侵入性,而且不能彻底解决问题,仍然有可能出现本地依赖和 aar 依赖的代码不一致问题。
Gradle 官方针对这种场景提供了更好的解决方式 DependencySubstitution,使用方式如下:
步骤1:
在 settting.gradle,添加如下代码:
// 加载本地 moduleif (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) }}步骤2:
在 app 的 build.gradle 添加以下代码
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 } } }}步骤3:
在 local.properties 里
moduleName=:testmodulePath=../AndroidStudioProjects/TestProject/testModule
到这里就大功告成了,后续只需要在 local.properties 里开启和关闭,即可实现 aar 模块本地依赖调试,提交代码也不用去手动修改回 aar 依赖。
“Androd Gradle模块依赖替换如何使用”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!
边栏推荐
- < Sicily> 1001. Rails
- Homekit and NFC support: smart Ting smart door lock SL1 only costs 149 yuan
- 4k-hdmi optical transceiver 1 channel [email protected] Hdmi2.0 optical transceiver HDMI HD video optical transceiver
- Go write permissions to file writefile (FileName, data, 0644)?
- Chinatown hiking: feel the strong Chinese flavor in the exotic New York
- The redis keys command should be used with caution in the production environment. It is best to shield it
- A bug development means that the user will not operate like this, and there is no need to repair it. How should testers respond?
- If there is a problem with minority browsers, do you need to do a compatibility test?
- R语言使用MatchIt包进行倾向性匹配分析(设置匹配方法为nearest,匹配倾向性评分最近的对照组和病例组,1:1配比)、使用match.data函数构建匹配后的样本集合
- Homekit supports the matter protocol. What does this imply?
猜你喜欢

#云原生征文#深入了解Ingress

「开发者说」钉钉连接器+OA审批实现学校学生假勤场景数字化

Solve "thread 1:" -[*.collectionnormalcellview isselected]: unrecognized selector sent to instance 0x7F "

Follow the promotional music MV of domestic tour in Thailand and travel to Bangkok like local people

Go write permissions to file writefile (FileName, data, 0644)?

Hanyuan hi tech 1-way uncompressed 4k-dvi optical transceiver 4K HD uncompressed DVI to optical fiber 4k-dvi HD video optical transceiver
![解决“Thread 1: “-[*.CollectionNormalCellView isSelected]: unrecognized selector sent to instance 0x7f”](/img/35/65511c49eca5ae8a1896d776b479d9.jpg)
解决“Thread 1: “-[*.CollectionNormalCellView isSelected]: unrecognized selector sent to instance 0x7f”

Excel-vba quick start (I. macros, VBA, procedures, types and variables, functions)

The two 985 universities share the same president! School: true

Analyse et résolution des défaillances de connexion causées par MySQL utilisant replicationconnection
随机推荐
夏日炎炎玩转新加坡:盘点室内景点和夜游好去处
测试时间不够怎么办?
R language uses matchit package for propensity matching analysis (set the matching method as nearest, match the control group and case group with the closest propensity score, 1:1 ratio), and use matc
Go write file permission WriteFile (filename, data, 0644)?
[website architecture] the unique skill of 10-year database design, practical design steps and specifications
涉及第三方支付接口,怎么测?
Homekit and NFC support: smart Ting smart door lock SL1 only costs 149 yuan
What if the test time is not enough?
Transformers are RNNs (linear transformer)论文阅读
华三交换机配置SSH远程登录
16 channel HD-SDI optical transceiver multi channel HD-SDI HD video optical transceiver 16 channel 3g-sdi HD audio video optical transceiver
Lm05 former VIX (second generation product)
解决:Argument type ‘String‘ expected to be an instance of a class or class-constrained type
深入思考:《盖亚奥特曼》中部分情景深度分析及反射出的哲理与感悟
Germancreditdata of dataset: a detailed introduction to the introduction, download and use of germancreditdata dataset
R language uses the polR function of mass package to build an ordered multi classification logistic regression model, and uses exp function and coef function to obtain the corresponding odds ratio of
Principle analysis of three methods for exchanging two numbers
首次曝光!唯一全域最高等级背后的阿里云云原生安全全景图
The project experience of resume and several problems that testers should pay attention to in writing
C# 文件下载方式