Tips on organizing larger Android projects?

12,176

Solution 1

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.

Solution 2

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.

Solution 3

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.

Solution 4

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.

Solution 5

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.

Share:
12,176

Related videos on Youtube

Zsombor Erdődy-Nagy
Author by

Zsombor Erdődy-Nagy

C++, Java, Android developer. MSc in software engineering. Employed as engineer manager at Uber, Amsterdam. http://hu.linkedin.com/in/rzsombor https://github.com/rzsombor

Updated on April 10, 2020

Comments

  • Zsombor Erdődy-Nagy
    Zsombor Erdődy-Nagy over 3 years

    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
    Zsombor Erdődy-Nagy over 12 years
    Yes, this one's certainly helpful! I tought that I could only group entire projects together with working sets. But grouping together resources from projects is way better!
  • derekerdmann
    derekerdmann over 12 years
    Another useful way to jump to the declaration: move your cursor somewhere in the class or method name and press F3
  • Steven Byle
    Steven Byle over 10 years
    I use them all the time, verrrry helpful when you have too many packages ;)
  • eddy
    eddy about 9 years
    Thank you so much! @Vladimir please do you think you could help me here goo.gl/MAjgTh ??

Related