Tuesday, May 3, 2011

What Goes Into Source Control, Android?

From the very beginning of my Android App development I knew I would be releasing it into the market.  As such I wanted to keep it in source control.  I'll explain my reasons for that in another post, but here I want to talk about what exactly goes into source control, what to do if you inherit a project that needs cleaned up and finally, how to coerce Eclipse into helping you long term.

I had never created a project outside of Eclipse's new Android Project Wizard so what was part of it's overhead versus what was needed for someone else to build this project on a difference machine?  I asked a few guys around the office and Stack Overflow.  As is always the case I got, "whatever isn't required to build the project doesn't go into source control."  Thanks geniuses.  At least one of them actually pointed me to the official documentation from which I could start to cherry pick the fluff out of my project.  Here's the official documentation on what is required for your project: http://developer.android.com/resources/faq/commontasks.html#filelist

My development environment is Eclipse with the Subclipse SVN plugin and I'm using online repositories from both BeanStalk and Assembla.  A quick scan of my repository and I was a little bummed to find several things in there that did not need to be:

  • bin/
  • gen/
  • .classpath
  • .project
  • default.properties
  • proguard.cfg
A friend and longtime developer asked me why I wouldn't want .classpath included?  Our office has a mix of both Windows and Linux development platforms so I've tried to mimic that as often as possible when doing personal development so I'm familiar with the challenges faced by my colleagues.  Everytime I would sync my local machine after the alternate environment had updated the repo I had .classpath issues.  Some of this could be my own inexperience so if you know the way around this please share ;)

Back to the point ... I did some research and found that I needed a local SVN client in order to accomplish what I wanted to do.  The command is:

svn rm --keep-local {filename/folder}

Execute that for each of the files or folders you wish to get out of source control, but keep your local copy.  I had read on SO that you needed the trailing / after folder names, but I've found that to be inaccurate.  Simply listing the folder "bin" works and actually adding the trailing / does not.

After running the svn command to remove (rm) each of the items I wanted out of source control I executed a commit:

svn commit -q -m "Removing unwated files/folders from source control" .

The next thing I did was set the filesystem level properties to keep them from accidentally ending up in Source Control in the future, but it is leading somewhere.  You can execute the following command from your project folder to add the items to the ignore list:

svn pe svn:ignore .

Just add each item, 1 per line, as above again excluding the trailing / on folder names.

I had tried to do all these things in the SVN perspective from within Eclipse but it would not let me set file/folder properties.  That's what lead me through the exercise outline above.  My next goal was to start with a fresh project and get things into source in the easiest way possible.  As I dug through the entire process I found that I can actually add the ignore property from within the Team Sync perspective!  That's huge as it keeps me (and you) from dinking around at the command line unnecessarily.  After you've "shared" your project go into the Team Sync perspective, right click the project and choose synchronize.  In the left pane you will be presented with a list of files that will be placed under source control.  You can right click them and choose to ignore them.  From here I can control exactly what is and is not going to get into my repo.  That was a big win and almost perfect, but curiosity had me wondering if I could go further.

Eclipse can help by default!  If you look at the Team section in Eclipse Preferences you can add the items to the "Ignored Resources."  I added each item and again created a new project.  This time after sharing it and going to the Team Sync perspective I had only the items listed that were identified in the Android documentation.  Obviously you can start by just doing this and save yourself all the hoop jumping that I went through.