将本地图书馆计划添加为Android Studio中多个项目的依赖关系 [英] Add local Library Project as a dependency to multiple Projects in Android Studio
问题描述
我在Android Studio中创建了一个图书馆项目(目前为0.5.2),选择 File>新项目...> 将该项目标记为库
。
I created a library project in Android Studio (currently 0.5.2) by choosing File > New Project... > "Mark this project as a library"
.
我有另外两个非图书馆项目,我想添加一个依赖关系到这个图书馆项目。
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')
in MyProject/app/build.gradle
dependencies {
compile project(':library')
}
这篇关于将本地图书馆计划添加为Android Studio中多个项目的依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!