22

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.

Zsombor Erdődy-Nagy
  • 16,864
  • 16
  • 76
  • 101
  • don't group your source for each screen. You will than have the problem, that you can't organize classes you use multiple times and you will probably stop to reuse code – WarrenFaith Apr 11 '11 at 15:21
  • I think the most cost of a large project is increasing the compiling & packing time. If every time we must waiting half minute or more then see our device come up the first window of our application, it would be boring to developing. So for your Edit approach, does it significantly improved the compile time? – VinceStyling May 26 '15 at 03:57

5 Answers5

19

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.

Vladimir Ivanov
  • 42,730
  • 18
  • 77
  • 103
11

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.

Graham Borland
  • 60,055
  • 21
  • 138
  • 179
7

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.

Robby Pond
  • 73,164
  • 16
  • 126
  • 119
5

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.

Mark Mooibroek
  • 7,636
  • 3
  • 32
  • 53
  • 1
    Another useful way to jump to the declaration: move your cursor somewhere in the class or method name and press **F3** – derekerdmann Aug 10 '11 at 14:10
2

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.

yongmeetle
  • 31
  • 1
  • 3