如何在Android模块之间共享依赖项

编程入门 行业动态 更新时间:2024-10-24 12:21:59
本文介绍了如何在Android模块之间共享依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个Android应用程序模块(应用程序)和一个Android库模块(库).应用程序和库都包含以下相同的依赖项:

I have an Android application module (app) and an Android library module (library). Both app and library contain these same dependencies:

dependencies { compile 'com.squareup.okhttp:okhttp:2.4.0' compile 'com.squareup.retrofit:retrofit:1.9.0' compile 'io.reactivex:rxjava:1.0.13' compile 'io.reactivex:rxandroid:0.25.0' }

但是,当我尝试将该块添加到 project build.gradle时,它抱怨不知道编译" DSL.

However when I try to add that block to the project build.gradle, it complains about not knowing the "compile" DSL.

我要询问的是将此依赖项块放入PROJECT build.gradle中,以避免在每个模块的build.gradle中重复.

I'm asking about putting this dependencies block in the PROJECT build.gradle, to avoid repeating in each module's build.gradle.

推荐答案

您可以在库模块中定义共享gradle依赖关系,并且如果app模块将库作为依赖项,则无需重复指定所有内容.进一步讲,您可以创建一个通用"模块,该模块需要共享的gradle依赖项,并且同时具有应用程序&库模块需要通用模块.

You can define shared gradle dependencies in the library module, and if the app module has the library as a dependency, you won't need to specify everything twice. Taking this further, you could create a 'common' module that requires the shared gradle dependencies, and have both the app & library module require the common module.

更多推荐

如何在Android模块之间共享依赖项

本文发布于:2023-08-01 12:27:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1268327.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模块   如何在   Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!