将本地库项目添加为 Android Studio 中多个项目的依赖项 [英] Add local Library Project as a dependency to multiple Projects in Android Studio
问题描述
我通过选择 File > 在 Android Studio(当前为 0.5.2)中创建了一个库项目.新项目...>将此项目标记为库"
.
我有另外两个非库项目,我想为这个库项目添加一个依赖项.
I have two other non-library projects that I would like to add a dependency to this library project.
-My Library
-Project 1 (depends on My Library)
-Project 2 (depends on My Library)
我的目标是让每个项目保持独立并避免重复模块/代码.如果不将库模块复制到其他项目中,如何做到这一点?
My goal is to keep each project independent and avoid duplicating modules/code. How can this be done without copying the library module into the other projects?
更新:Android Studio 0.6.0 允许您导入模块,但这只是将模块源复制到项目中.
Update: Android Studio 0.6.0 allows you to Import a module, though, this simply copies the module source into the Project.
推荐答案
您还可以使用 project().projectDir 属性引用项目文件夹之外的库.如果您的外部库与您的项目相关,那么
You can also refer to a library outside of your project folder using the project().projectDir property. If your external library is relative to your project like so
- MyLibrary
- library
- MyProject
- app
在 MyProject/settings.gradle 中
in MyProject/settings.gradle
include ':library'
project(':library').projectDir = new File(settingsDir, '../MyLibrary/library')
在 MyProject/app/build.gradle 中
in MyProject/app/build.gradle
dependencies {
compile project(':library')
}
这篇关于将本地库项目添加为 Android Studio 中多个项目的依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!