Monday, June 25, 2012

Android Source code browsing

As an engineer,  most of the time you spend on browsing peers' code in your company. Sometimes we think that how these platforms(i.e Android, Java, etc.) have been written? Is there anyway of getting access of source code? Is there any advantage of this?
 Well, there can be certainly some advantages. I would say, you may consider the following points as  advantages.
  • First hand Information. Source code browsing reveals large-scale software program. 
  • Increases your conceptual understanding of platform.
  • Gives idea about how you can do things more precisely and efficiently. It increases your code writing skills.
  • Makes you learn the coding standard and convention followed by the platform.
  • Live examples .
  • You may eventually contribute to the platform enhancement.

There are two ways of browsing the source code:

  1. Copy/clone source code repo.
  2. Online source code browsing.

1. Copy/clone source code repo.

If you have prior knowledge of git/repo and greping code in source directory then this option would be useful for you. If you are not keen to learn Git then please proceed to the next section. You can clone the Android source repo from these two places. 
  • googlesource : If you want to clone the android googlesrouce repo you can follow instruction given here.
  • github : Go here. Select the repositiory which you want to clone. Click on the Readonly button.  You will find url in text field similar to this git://github.com/android/android-module-repository.git and then execute these commands:

$mkdir android-src
$cd android-src
$git clone git://github.com/android/android-module-git-repository.git 

2. Online Source code browsing.

There are various websites available for Android source code browsing. I have listed some of them here. These are arranged in order of their usefulness to developer.
  1. www.grepcode.com : I personally like this website since it is really easy to use and handy. You can see the member function and the directory/package structure on the same webpage. You don't need to navigate around. This website has categorized the source code in different groups based on the module and its functionality. In case you have used Eclipse as an IDE then you will take less time to understand the user interface. There are four tabs Outlines, Files, Hierarchy and Comments, as we have in Eclipse IDE. In Outline tab you can browse methods and variables present in the class and its accessibility(private, protected and public). The File tab shows the folder/directory structure. The Hierarchy tab shows  how a particular class has been derived from other class along with its inheritance hierarchy. The Comments tab may not be so useful however it helps you to comment using your Facebook login. There are four links available on the top of the code frame. They are Find usage, Diff, Raw, Download and HTML widget. Find usage link provides you code snippet giving you the idea about the usage of particular method/variable  in different places. The Diff link provides the difference between the different code versions. The Raw link opens a new browser window which contains the source code.  The Download link itself suggest  what it does. The HTML Widget helps to share the source code. The most useful feature is that you can check the definition of class/variable by clicking on its name. This website also has java source code.
  2. Androidxref.com : This website has index Android 2.3.6, 4.0.4 and 4.1.1 source code. It provides almost similar features as provided by grep.com
  3. www.java2s.com : This is also a good resource. I will rank this site on the second place. It doesn't provide as many features as grepcode does. But still this website can be used for code reference. It also provides code examples which can be really helpful sometimes. 
  4. www.github.com :  This site is not basically designed for code browsing purpose but it can be used for the same. This website organizes the files in the same way as your hardrive does.(I host my source code on github. ;-) }

If you are really into Android and want to browse code on your Android phone then this application can be very handy. You can browse the code on the go.
These two sites java2s and grepcode host java source code and are really useful tools in your armour.

If you want to install git in Ubuntu machine, you may execute command below: 
$sudo apt-get install git

Similar topic:
Python package/library source code browsing

Your valuable comments are always welcomed. It will help to improve my post and understanding.

"By three methods we may learn wisdom: First, by reflection, which is noblest; Second, by imitation, which is easiest; and third by experience, which is the bitterest."
By : Confucius