如何在 Android 模块之间共享依赖项 [英] How do I share dependencies between Android modules

查看:75
本文介绍了如何在 Android 模块之间共享依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Android 应用程序模块(app)和一个 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.

推荐答案

你可以在library模块中定义共享gradle依赖,如果app模块有library作为依赖,你就不需要指定两次了.更进一步,您可以创建一个通用"模块,它需要共享的 gradle 依赖项,并且同时拥有 app 和库模块需要公共模块.

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 模块之间共享依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆