我应该如何组织 Android 项目(包括库)的源代码控制?
我需要一些帮助来找出组织我的 Android 项目的最佳方式(或最佳实践)。为了简单起见,假设我的 Android Eclipse 工作区是 C:\Android\Projects\。在该文件夹中,我喜欢将应用程序与库分开,并且还有另外两个文件夹,C:\Android\Projects\Applications
和 C:\Android\Projects\Components
。
对于一个项目,我已从 GitHub 将一个库克隆到 Components
文件夹中,假设 C:\Android\Projects\Componentes\SampleLib
(该文件夹内有两个文件夹 TheLib
和 TheLibExample
)。我的应用程序创建到 C:\Android\Projects\Applications\MyTestApp 中。然后,我按照这些说明将该库包含到应用程序中。
现在假设我想使用 GitHub 与开源社区分享我的应用程序。我将创建一个存储库,并将 C:\Android\Projects\Applications\MyTestApp 中的所有内容推送到某个存储库中。
如果有人想分叉我的应用程序甚至帮助我,它将需要库来编译和运行它,这不包含在我的项目本身中。 default.properties
文件将包含类似 android.library.reference.1=../Components/SampleLib/TheLib
的内容,并且有人也需要手动克隆该库他需要将其放置在相同的相对路径中,否则会弄乱我的应用程序的源代码控制。
我能想到解决这个问题的唯一方法是像这样组织我的工作区:
C:\Android\Projects\Applications\MyTestApp\TheApp
C:\Android\Projects\Applications\MyTestApp\TheLib
C:\Android\Projects\Componentes\SampleLib
并且我的存储库应该填充来自 C:\Android\Projects\Applications\MyTestApp\
的内容。
但是当库更新时会发生什么呢?我不能简单地提取新的更改,我需要将它们复制到 TheLib
文件夹中。在之前的文件夹组织中,不需要这样做,因为我引用的是原始克隆存储库而不是副本。
那我该怎么办?我应该选择第一个选项,让任何人分叉我的项目,按照他们认为合适的方式处理库依赖项,还是应该选择第二个选项,当原始文件夹从其中提取更改时,通过保持两个文件夹同步来为每个人提供更多工作存储库?
I need a little help figuring out the best way (or best practice) to organize my Android project. For simplicity sake, let's say my Eclipse workspace for Android is C:\Android\Projects\
. Inside that folder I like to separated applications from libraries and I have two other folders, C:\Android\Projects\Applications
and C:\Android\Projects\Components
.
For one project I have cloned a library from GitHub into the Components
folder, let's say C:\Android\Projects\Componentes\SampleLib
(inside that folder there's two folders TheLib
and TheLibExample
). And my app is created into C:\Android\Projects\Applications\MyTestApp
. Then I included the library into the app by following these instructions.
Now let's say I want to use GitHub to share my app with the open-source community. I'll create a repository and push everything from C:\Android\Projects\Applications\MyTestApp
into some repository.
If someone wants to fork my app or even help me, it will need the library to compile and run it, which is not included in my project itself. The default.properties
file will have something like android.library.reference.1=../Components/SampleLib/TheLib
and that someone will need to manually clone that library too and he would need to place it in the same relative path, otherwise it would mess up source control for my app.
The only way I can think of solving this issue is to organize my workspace like this:
C:\Android\Projects\Applications\MyTestApp\TheApp
C:\Android\Projects\Applications\MyTestApp\TheLib
C:\Android\Projects\Componentes\SampleLib
And my repository should be filled with the contents from C:\Android\Projects\Applications\MyTestApp\
.
But what happens when the library is updated? I can't simply pull the new changes, I need to copy those into TheLib
folder. In the previous folder organization this would not be needed as I was referencing the original cloned repository and not a copy.
What should I do then? Should I go with option one and let anyone forking my project deal with the library dependency as they see fit, or should I go with the second one and give everyone more work by keeping two folders in sync when the original one pulls changes from the it's repository?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许 git 子模块可以解决你的问题。
Maybe git submodules will solve your issue.
我个人认为Android的库项目是一个失败的设计。可笑的是,我想要引用/使用其他代码片段的唯一方法是获取另一个整个项目并在 IDE 配置级别设置所有内容。什么是图书馆?它应该是一个以归档格式编译和打包的可重用组件。根据他们的重要说明库项目存储位置,我不认为有一个简单的解决方法,我们可以打破束缚并将该库作为真正的库进行管理。如果您的库不是那么 androidized,请尝试将其编写/构建为普通 jar 库,并使用 maven 管理 jar 库构建/发布和项目依赖项。
嗯,Google 将其称为 Android Library Project,而不是 Android Library 是合理的。
Personally I think Android's library project is a FAIL design. It is ridiculous that the only way I want refer/use other piece of code is to get another entire project and set everything up at IDE configuration level. what is a library? it should be a reusable component compiled and packaged in a archive format. According to their important note Library project storage location, I don't think there is a easy workaround that we can break the tie and manage the library as a real library. If your library is not so androidized, try to write/build is as a plain jar library and use maven manage the jar library build/release and project dependencies.
Hmmm, it is reasonable that google call it Android Library Project, not Android Library.
我个人认为 git 子模块并不完全为库依赖项提供一个非常易于使用且功能强大的系统。
Git 子树是更好的选择。我发现一个非常有用的指南解释了如何做到这一点。
基本上,您可以创建一个包含依赖项的子文件夹,并在该子文件夹内克隆存储库:
然后,在此示例中,您将在
vendor/
内拥有两个存储库/库;您只需将它们添加到您的 IDE/构建系统中即可。Git 分支和修改比子模块更容易、更直接。
我什至创建了一个小脚本,它可以针对库列表自动执行此过程。
I personnaly think that git submodules don't entirely provide a very easy to use and powerful system for library dependencies.
Git subtrees are a better alternative. I found a very useful guide that explains how to do that.
Basically you can create a subfolder containing your dependencies, and clone repositories inside that subfolder:
Then, you'll have the in this example two repos/libs inside
vendor/
; you just need to add them to your IDE/build system.Git branching and modifications are much easier and more straightforward than with submodules.
I've even created a small script that automates this process for a list of libs.