Wednesday, April 6, 2011

How to Work on an Android Project from Multiple Computers

Note: I would never recommend this solution for an actual development company.  This really is intended for personal projects, or developing a small-scale app with one or two developers at most. As always, try this at your own risk, as I will not be responsible for any lost, corrupted or otherwise broken projects.

When I started developing my first Android application, I quickly found that it would be really nice to be able to work on the same source code from multiple computers, without having to copy things to an external hard drive, or uploading it somewhere and then downloading it and hoping that everything is in sync.

I already had a free Dropbox account (available here) that I had been using to sync a small number of files on separate computers, so I started thinking -- why not keep my Android project in my Dropbox?  Would it work? Would there be any "gotchas"?  If nothing else, I thought it was worth a try.

So, when I created my Android project in Eclipse (available here) I decided to set it up in my local Dropbox folder.  I added a few files, built the project and ran it -- so far so good.  I then opened the Dropbox app on my computer and let the syncing do its thing.  In my case, not only was I dealing with two different computers, I was also dealing with two different OSes.  My desktop computer is running Windows, while my laptop is running Mac OS X.  I figured if anything could go wrong, it would in this scenario.

Before I go any further, I'd like to mention that I also wanted to use some kind of Source Control (the ability to check in and check out files, and mark certain versions of projects as version numbers that corresponded with the versions of my app).  Eclipse seemed to have some built-in functionality for using CVS Source control, so I started on the hunt.  In short, I ended up using WinCVS / MacCVS (available here).  Setting up the CVS server isn't too complicated, so I'll leave that to you.

After you have the CVS portion set up (Server and functionality within Eclipse), you should be able to Right-Click on your project and select Team -> Share Project.  Once you do this, you'll have to step through the wizard, but when you're done, you should have a version-controlled Android Project sitting in your Dropbox.

Now for accessing that project from your second computer.  In my case, I installed Dropbox, Eclipse and the MacCVS server and configured everything similar to that of my Windows PC.  After everything finishes syncing in your Dropbox, open Eclipse and go to File -> New -> Project.  From the list of options, select CVS then Project from CVS.  Select Use existing repository location (which should have your local repository after setting up CVS), choose your local repository and click Next.  Select Use an existing module, and select the project you created on your first computer and click Finish.  This should create a new Project in your workspace complete with the current versions of your source code.

So -- you should now be able to work freely on your code from both computers, and commit changes as you make them, and watch them sync to your Dropbox.

Potential Gotchas:

  • Each time you log into a different computer from the last time you committed, you'll need to Update your project by Right-Clicking on the project, and then select Team -> Update.
  • In my case, running on one Windows computer and one Mac, I had very different build paths for my projects.  If you're doing something similar, you may or may not want to check in your project as a whole (instead, just check in individual files as you change them).  If you do happen to check in your project as a whole, you'll just need to remember to update the build properties on your other computer the next time you use it.
  • When you actually build your application and install it on a phone through Eclipse, the apk will most likely have different signatures from each computer, so you'll also want to uninstall any previous versions on your phone before switching computers.  If you just use the simulator, this is a non-issue.
  • Speaking of Signatures -- when you go to Export a Signed APK, you'll have to create (or use an existing) keystore.  I also keep this in my dropbox so that no matter which computer I'm on, I can always export an APK ready to be uploaded to the Market.
In general, I imagine this technique could also be applied to iPhone/iOS development (between Macs obviously), or other Java-based projects, and more.


jarvisteve said...

I do something similar, but what annoys me is the need to change the workspace path each time I switch computers. Is there some way to set an environment variable and set the workspace to that? I thought I was on to something with External Tools, but that didn't work like I hoped it would (or I don't know how to use it properly). It may be an Android only issue too, since it's the path in Android settings that needs to be changed every time.

Matt Augustine said...

Totally agree! It's pretty annoying, especially if you're switching back and forth a lot. I haven't found anything to smooth the transition, but if you do, please let me know!

Maria Torres said...

This may help someone having the problem with the path switching, but only if both computers work with the same OS.

I installed Eclipse outside Dropbox and just the workspace inside. I also renamed one of my computers so both have the same name. That solved my problem of having to switch and switch.

i4 consulting said...

Excellent post, some great resources. Styling Blog the right way is the key,But somethings are wrong You really wrote every little detail,  php Website development in Singapore