Thursday, August 30, 2012

Add Git Branch to Bash prompt and a git goodie - SourceTree

Adding git branch to your bash prompt has become easier than before.

Edit your ~/.bash_profile to add following code

# Set git autocompletion 
if [ -f /usr/local/git/contrib/completion/git-completion.bash ]; then
  . /usr/local/git/contrib/completion/git-completion.bash


if [ -f /opt/local/etc/bash_completion ]; then
    . /opt/local/etc/bash_completion

PS1='\[\033[34m\]\w\[\033[31m\]$(__git_ps1)\[\033[00m\]\$ '

It not only adds branch name but also indicates the current status of your project. For example, when you add files to staging area, + is added after branch name. 
If you make further changes to staged files, it adds * after branch name to indicate there are unstaged files.

The above script also enables Git autocompletion which will help saving some keystrokes.

If you prefer GUI tool and even if you prefer command line, SourceTree is a must have tool for Mac users. It shows you all branches, their commits, the changes. You can do everything using it.

For newbies, it will make using git a lot more fun!

Tuesday, August 28, 2012

Getting Started with Android App Development

The beauty of Android development is that you are not restricted to any particular development environment. You can use any operating systems and any IDE you like. But since we will be writing Java code, Eclipse is a natural choice.

All you need are these 4 things

- Java SDK 6
- Eclipse IDE
- Android SDK
- Eclipse ADT plugin
- git (optional but recommended)

Get Java SDK

If you don't have Java SDK, getting it is simple. Download it from

Download Eclipse IDE

Download Eclipse Classic from
If you are using Mac or Linux, and not sure if you are running 64bit or 32bit machine, inside Terminal run this command
$ uname -a
The output will tell you which eclipse binary you should download. Unzip and you have Eclipse.

Download Android SDK & Tools

Next step is to download Android SDK from
Unzip the file you just downloaded. You should see android-sdk-mac folder. Copy it to a location where you want to download all other Android Development tools. Using terminal, navigate to tools folder inside android-sdk-mac and run android program
~/dev/android-dev/android-sdk-macosx/tools $ ./android  
This opens up Android SDK Manager. It shows you all installed components, the updates and also lists all available versions of Android SDK. This is where you will select what you need to download that includes, plain SDK, sample code, SDK source code, system images, Google APIs and also vendor specific components. If that's too much to take in, make sure you select for both Android 4.1 and Android 4.0.3
  • Documentation from Android SDK
  • SDK platform
  • Samples for SDK
  • ARM EABI system image
And under Tools category, select
  • Android SDK Tools
  • Android SDK platform-tools
And click install packages, next Accept all and let it finish.

The final step is to install Eclipse ADT plugin which makes Android development tools (mode on that later) part of the IDE for easy access. 

Download the ADT Plugin

  1. Start Eclipse, then select Help > Install New Software.
  2. Click Add, in the top-right corner.
  3. In the Add Repository dialog that appears, enter "ADT Plugin" for the Name and the following URL for the Location:
  4. Click OK.
    If you have trouble acquiring the plugin, try using "http" in the Location URL, instead of "https" (https is preferred for security reasons).
  5. In the Available Software dialog, select the checkbox next to Developer Tools and click Next.
  6. In the next window, you'll see a list of the tools to be downloaded. Click Next.
  7. Read and accept the license agreements, then click Finish.
    If you get a security warning saying that the authenticity or validity of the software can't be established, click OK.
  8. When the installation completes, restart Eclipse.

Configure the ADT Plugin

After you've installed ADT and restarted Eclipse, you must specify the location of your Android SDK directory:
  1. Select Window > Preferences... to open the Preferences panel (on Mac OS X, select Eclipse > Preferences).
  2. Select Android from the left panel.
  3. You may see a dialog asking whether you want to send usage statistics to Google. If so, make your choice and clickProceed.
  4. For the SDK Location in the main panel, click Browse... and locate your downloaded Android SDK directory (such asandroid-sdk-windows).
  5. Click Apply, then OK.

Install Git

Git is an open source version control system. It works best for small projects as well as massive projects like Android platform itself. It will help you maintain different versions of your source code. In case you would like to download the Android source code, you will require git. It's very easy install.
Download it from below site and install it using package manager.

We will talk s more about git once we start developing actual applications. 

Next, we will talk about some Android Development Tools and will run our first Android app.