问题描述
我有两个项目 A 和 B,并且想通过库项目 C 在它们之间共享一些代码.这样做的正确方法是:
I have two projects, A and B, and would like to share some code between them via a library project, C. What is the proper way to do this such that:
- A、B 和 C 都在不同的项目中.(根本不在同一个目录中)
- 在 A 或 B 中自动使用对 C 的更改,而无需重新导入 C.
我对 Android Studio 还很陌生,在这里遇到了各种各样的问题.我真的只想使用位于项目根目录之外的源代码.谢谢!
I'm fairly new to Android Studio and I've been running into all sorts of issues here. I really just want to use source code that is located outside the project root. Thanks!
推荐答案
这听起来像是提出(并回答)的问题此处.
This sounds like the question asked (and answered) here.
总结 Scott Barta 的回答:
To sum up Scott Barta's answer:
settings.gradle:
include ':module-custom-lib'
project(':module-custom-lib').projectDir = new File(settingsDir, '../../../libraryProject/workspace/projectSrc')
A 和 B 的 build.gradle:
dependencies {
compile project(':module-custom-lib')
}
因此,假设文件结构如下:
So, assuming a file structure like this:
+-- AndroidStudioProjects
| +-- CoreLibs
| +-- app (empty)
| +-- myJavaCoreLib
| +-- anotherJavaCoreLib
| +-- AndroidApp1
| +-- app
| +-- AndroidApp2
| +-- app
| +-- AndroidApp3
| +-- app
...代码将是:
settings.gradle:
include ':coreLib'
project(':coreLib').projectDir = new File(settingsDir, '../CoreLibs/myJavaCoreLib')
build.gradle 在 AndroidApp[1、2 和 3] (你的 A 和 B):
build.gradle in AndroidApp[1, 2 and 3] (your A's and B's):
compile project(':coreLib')
这篇关于Android Studio:在项目根目录之外添加库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!