关于组织大型 Android 项目的建议?

发布于 2024-11-01 01:41:58 字数 698 浏览 4 评论 0原文

我当前的项目变得非常大。我有数十个活动、适配器、片段、布局 xml 和其他资源。

在我之前的(较小的)项目中,我使用 1 个包/1 个类别的样式来组织内容。所以我有 com.stuff.xy.adapter、com.stuff.xy.activity 等等。现在这些包包含太多的项目,我发现自己浪费了大量的时间在包层次结构中搜索特定的类。

我使用 Eclipse,并且可以使用一些快捷方式(例如转到类定义),但这些往往是视情况而定的(我无法使用它来快速跳转到布局定义 xml)。

您能否分享一些有效组织大型项目的技巧?或者可能有一些插件? (例如,如果我可以将处理特定应用程序屏幕的源文件(适配器、布局、活动和片段代码)分组在一起,这样我就可以快速打开它们,这可能会有所帮助)

编辑:经过几个月的开发大型项目

首先,我尝试使用 Eclipse 来处理工作集。这并没有真正解决我的问题,我的问题是我们的单个 Android 项目太大了,包含许多资源、类、接口等。在单个项目的上下文中搞乱工作集花费了太多时间,我认为它们主要用于在单个工作区中组织项目。

从长远来看,我们将庞大的单个项目分成许多较小的 android 库项目和依赖于所有这些较小项目的单个“主应用程序”项目。这样我们就可以在这些库项目(有许多布局、值、样式仅在应用程序的某些部分使用)和代码之间分配资源。我还创建了一个所有其他库所依赖的基础库,并包含应用程序每个部分所需的资源和(基)类。

My current project is getting awfully large. I have dozens of activities, adapters, fragments, layout xmls, and other resources.

In my (smaller) previous projects I organized stuff with a 1 package / 1 category style. So I had com.stuff.xy.adapter, com.stuff.xy.activity, and so on. Now these packages contain too many items, and I find myself wasting considerable amounts of time searching for a specific class in the package hierarchy.

I use Eclipse, and there are some shortcuts one can use (go to class definition e.g.), but those tend to be situational (I can't use that to quickly jump to a layout definiton xml).

Could you share some tips on organizing large scale projects efficiently? Or some plugins for this perhaps? (It might help for example if I could group together source files that deal with a specific application screen - adapters, layouts, activity and fragment code - so I can quickly open them)

EDIT: After many months developing large projects

First I tried to go with working sets with Eclipse. It didn't really cut it for me, my problem was that our single Android project was simply too big, containing many resources, classes, interfaces, etc. Messing around with working sets in the context of a single project just took too much time, I think that they're mainly useful to organize projects in a single workspace.

On the long run we separated our huge single project into many smaller android-library projects and a single "main application" project that depended on all these smaller ones. This way we could split the resources among these library projects (there were many layouts, values, styles that were only used in certain parts in the application) and code of course. I also created a Base library, that all other libraries depended upon, and contained resources and (base)classes that every part of the application needed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

遇到 2024-11-08 01:41:58

对于我的所有 Android 项目,我更喜欢按以下结构对代码进行排序:

com.company.projectname 是应用程序的包。
底层包:

model - 我的所有业务对象

logic - 实现业务逻辑的服务和对象

screens - 项目的所有活动。如果活动需要适配器等,则每个活动都放置在屏幕包下的单独包中,并将相关内容放置在同一个项目中。

tools - 包含实用程序类的包。 SettingsUtil等。

在包的根目录中,我通常有带有常量的 Constants.java 接口。

For all my android projects I prefer to sort code in the following structure:

com.company.projectname is the package of the application.
Underlying packages:

model - all my business-objects

logic - services and objects implementing business logic

screens - all the activities of the project. If activities require adapters and so on, then each activity is placed in a separate package under screens package and the related stuff is placed to the same project.

tools - package with Utility class. SettingsUtil and so on.

In the root of the package I usually have Constants.java interface with constants.

预谋 2024-11-08 01:41:58

在 Eclipse 中,您可以使用 工作集,用于在项目资源管理器视图中过滤源/布局/资源文件。这比包更强大一些,因为它可以操作所有文件,包括布局和图像资源,而不仅仅是 java 源文件。

例如,您可以创建一个 Home 工作集,其中包含 HomeActivity.java、HomeAdapter.java、res/layout/home.xml、res/drawable/home_icon.png 等。

In Eclipse, you can use Working Sets to filter your source/layout/resource files in the Project Explorer view. This is a bit more powerful than packages, since it operates on all files including layout and image assets, not just java source files.

For example, you could create a Home working set which contains HomeActivity.java, HomeAdapter.java, res/layout/home.xml, res/drawable/home_icon.png, etc.

千寻… 2024-11-08 01:41:58

只是另一个提示。

使用 Ctrl-Shift-R 快速打开资源(您会看到一个自动完成下拉菜单),使用 Ctrl-Shift-T 快速打开 Java 类。该列表还将使用最近打开的文件自动填充。

Just another tip.

Use Ctrl-Shift-R to quickly open a resource (you get an autocomplete drop down) and Ctrl-Shift-T to quickly open a java class. The list will also auto-populate using the most recent opened files.

此岸叶落 2024-11-08 01:41:58

也许是一个提示:快速转到 Eclipse 中的声明

在将悬停在类或方法上时按住Ctrl。 1 秒后,您将看到一个带有开放声明/开放实现的弹出窗口

在大型项目中非常有用。

对于其余的,我建议使其直观并对包中的所有活动以及所有计算进行排序,例如

Maybe a tip: to quickly go to a declaration in Eclipse

Hold Ctrl while hovering over a class or method. After 1 sec you get a popup with open declaration / open implementation.

Very useful in large project.

For the rest i recommend just making it intuitive and sort all Activities in a package aswell as all calculations e.g.

氛圍 2024-11-08 01:41:58

对于您担心的“我无法使用它来快速跳转到布局定义xml”,您可以单击布局xml的名称,然后ctrl+shift+R将引导您到该定义页面。

for your concern "I can't use that to quickly jump to a layout definiton xml", you can click the name of the layout xml, then ctrl+shift+R will lead you to that definition page.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文