Getting access to the android source code is not as straight forward as it may seem for an open source project. No source is shipped with the SDK tools and using eclipse you only end up with the decompiled skeletons generated from the binary platforms jars when you try to look at the code definitions.
Get the Source. There are a number different ways to get the source, as you will need to grab the version which is consistent with what you are coding. Using git you can clone the source tree and then open up the branches which are appropriate to the SDK you are developing against.
Clone the git tree using the following command :
git clone git://android.git.kernel.org/platform/frameworks/base.git android-base
The syntax is git <command> <source> <target-dir>. So in this example the frameworks/base repository would be downloaded to "./android-base". At this point the head(master) version of the code will be availble to browse.
Browse the full android git repository here
Get the SDK version. Now a local copy of the repository is available you need to get the appropriate SDK version.
To list the branches available remotely run the following command from the directory you cloned base.git to (android-base in above example) :
git branch -a
This will show the list of branches with the star being one currently checked out.
* eclair
eclair-release
master
remotes/origin/HEAD -> origin/master
remotes/origin/cdma-import
remotes/origin/cupcake
remotes/origin/cupcake-release
remotes/origin/donut
remotes/origin/donut-plus-aosp
remotes/origin/donut-release
remotes/origin/donut-release2
remotes/origin/eclair
remotes/origin/eclair-passion-release
remotes/origin/eclair-release
remotes/origin/eclair-sholes-release
remotes/origin/eclair-sholes-release2
remotes/origin/froyo
remotes/origin/froyo-release
remotes/origin/master
remotes/origin/release-1.0
To then move to the branch version for the SDK you are developing against run :
git checkout eclair-release
For the command line averse another way to do this is to add the repository in eclipse. In the Git Repository Explorer perspective right click in the Git Repositories panel elect Add Git Repository :
Browse to where you cloned the git repository to on your local machine and select the repository, and hit ok, eclipse will import the repository. Now if you open up the repository and select the branch that corresponds to the SDK you are developing against :
So for example Android 2.1 (SDK 7) corresponds to the branch eclair release. Right click and select Checkout this will revert all the source code in the repository to how it was at the time of the branch.
This should then allow the source code you browse (with or eclipse or from the file system) to match up with the exception line numbers being thrown from the dalvik VM <if your code throws exceptions :-) >.
No comments:
Post a Comment