Working With The Android Source Code

Written by:  • Edited by: Simon Hill
Updated May 3, 2011
• Related Guides: Android | Source Code

Ever wonder what Google Android source code looks like so you can see how internal apps are made? Thanks to the open source platform that the Android Mobile OS is built on, you can get this information. This how-to-guide shows you how.

In this series of articles we are having a look at some tools and resources that make our Android development projects more easy to build. Now its time to talk about the Android source code. Android is an Open Source platform, this means that the source code is available for everybody, like in a GNU/Linux system. Everybody can download, modify and create his “own Android platform”. Even more, we can help the Android community and fix for ourselves code mistakes we can find within this code.

This time, we are going to have a look at the code, to see how Android Apps are put together.

 

Repository

In the source code web page, we can find all information we need to get the source code. The whole code is about 2Gb, and we will need 6Gb to compile it. Now, we can only use Unix-like machines to compile it, so if we are working under Windows, we can not do that. In our case, we want only have a look to the source code, we don't want (for now) to compile it.

Lets have a look to the Repository web page we can find a large list of projects. They are the source code of the kernel, framework,libraries, Applications and much more!

First of all we have to know what we are looking for, because if we don't know that, we can become crazy looking inside the project folders.

Imagine that we want to know how the AlarmClock is programed. We find this project as platform/packages/apps/AlarmClock.git.

Inside every project, we can find deferents tags “Summary, shortlog, log...” we are interested in the “summary” and “tree” ones. Why the “summary”? Here we can find all information about the project we need. In the “tree” tag, we can surf trough the project folders and files.

We have to take account that this code is always changing, they are working with a more advanced SDK than ours. So maybe, some of the “main” branches code would not work in our applications because they depends of the news SDK classes. If we want to get the source code of the public SDK (1.0) we have to go to “release-1.0” line, in the “summary” tag.

If we surf trough the “tree” tag, we can see every java, xml and resource files of the project. We can download them individually or as a package.

Getting the source code

We have to specify the source we want to download, is it a source code of an older version of the SDK? Or is it the source code of the actual development SDK? We are using the “older” version of the SDK, 1.0 (the public one). So in this case we can just download the packages looking for the snapshot tag. This will download the project branch.

If we want to download the, still in development source code, we have to use a external tool:

Git

We can use this tool in all Operating Systems.

So, once we have this installed, to download a full branch of a project just use this command in the command line:

git clone git://android.git.kernel.org/ + project path.

Once this is done, we can have a look inside the folders and files more easily than using the web browser.

Some Hints

We do have to take several other aspects into consideration.

-The main branches of the repository are still in development, so they are using a different SDK that the public one. If you want to get the code from the public SDK (1.0, now) Look in the “release-1.0” link.

-Some classes are NOT PUBLIC like android.os.ServiceManager, android.view.IWindowManager, etc, they are implemented in the mobile devices, but not present in the SDK .jar. This is because these classes are private APIs and may change/disappear in any release


Comments

Showing all 22 comments
 
Jeremy Sword Dec 30, 2010 10:58 AM
compiling source code for app
So if I cloned the Alarm Clock branch to my computer with Git, could I compile the app source with Eclipse and the droid SDK on a Windows machine or would that have to be done on a Linux machine?
Alok Dec 9, 2010 10:38 AM
is a gmail search code(mail functionality) in android froyo
I wanted to know if a gmail search code functionality is present in froyo code or not and if it is than do let me know where it is present.Am new to android...
h4uw1n3 Dec 5, 2010 4:09 PM
Android OS
i know that my questions might be sound so stupid, i just installed android os to my tablet, but it seem didn't work, wifi, camera, audio, touchscreen...

i just looking a way to make it work, and i have no idea about linux, even so, i just wanna know,that's why i keep looking. it's working fine on other netbook, mostly eee series... with windows i just need to looking the driver for my hardware, but how about android? do you have any idea? about kernel, git etc.

thanks... :D
ravi patel Dec 1, 2010 3:58 AM
how to setup ubuntu machine for android project development
hi


i am new in ubuntu for setting up development environment that is require by android project so plz tell me all information in details i already tried most of method for setting git but not successful .. so plz give me step by step guide
Roa Sabri Nov 8, 2010 6:52 AM
what is an android
please send complete information about android,books if found.
this is my e_mail:
roasabri@gmail.com
Jbeerdev Oct 18, 2010 4:56 AM
RE: Working With The Android Source Code
Hi Chris!

You should check hoy native alarm clock is done:

http://android.git.kernel.org/?p=platform/packages/apps/AlarmClock.git;a=summary

Here is the complete source code.

good luck.

And ask any question about coding if you have any problem or doubt
Chris. Oct 18, 2010 4:40 AM
Thank you and ask something
Thanks jbeer.
I am a university student who in study android application in Korea university,
During the reading your blog, i found some questions from your articles.
Acually, I don't have any idea about andoird applications. But unfortunately, i have to make a alarm for android. So just i want to get some information about alram. Can you help to me?
Why don't you open some alram code for everyone?? First of all I need to study for alram code.
I hope you to help us..
Give some comment.!! PLZ..
Jbeerdev Sep 21, 2010 7:58 AM
RE: Working With The Android Source Code
Hi Prathap Chowdary

You should have basic Java and XML knowledge. Once you control Java, you can go deeper in Android structure and "way-to-do-things".
Prathap Chowdary Sep 21, 2010 7:49 AM
hi
how to work with android . what are the basic skills required ........
Jbeerdev Aug 31, 2010 4:29 AM
RE: Working With The Android Source Code
Hi m.mohamed shajahan.

Android programming languaje is Java-based, so if you know Java, it will be easier for you. And here you have a list of articles ordered by topics:

https://sites.google.com/site/josebcortes/articulos/the-bright-hub

Introduction and User Interface are the basics.

Hope it helps!
m.mohamed shajahan Aug 31, 2010 4:18 AM
reguesting inormation
i going to develop application project in android platform... i need to know"what the basics knownledge i need to learn for doing the project...
Jbeerdev Mar 28, 2010 1:27 PM
RE: Working With The Android Source Code
Hi Krishna

Could you explain yourself a bit more? Do you mean to trigger a "onClick" event by code, and not by clicking in the screen?
Prabhakar Mar 24, 2010 3:52 AM
Android Source Codes
Hello,

We provides android source codes, for more details contact prabhakar@tritonetech.com
Sam Jan 22, 2010 11:06 PM
set off alarm
Hi , i have some a date time stored in a sql lite database, is it possible to set off an alarm or notification at this time if so, how would you do it? thanks
Krishna Raj Dec 30, 2009 1:37 AM
Automating Testing using Android
Hi Jbeer,
I would like to know, whether it is possible to trigger events from commands or scripts (without key press or mouse events).

Thanks in Advance,

K.R
Jbeerdev Dec 5, 2009 4:44 PM
RE: Working With The Android Source Code
Hi Julian.

I wrote some weeks ago a article that maybe could help you:

http://www.brighthub.com/mobile/google-android/articles/52883.aspx

Its about a Framework a colleague create to work with Android DataBases.

Let me know ifs helpful.
Julian Varga Dec 5, 2009 2:11 AM
Thanks!!
That's exactly what I need, and I know it is probably easy to do. My problem is that I'm just starting, but what I've read so far is so great that motivates me to keep trying to learn more and more about Android. I have the database, but I don't really know how to import it to SQLite format in order to see it in my program (if that's necessary). I've read something about using raw data, but it wasn't so clear on how to do it. I'm planning on using a spinner to select the steel shapes and two radio buttons to select either column or beam. The rest of the layout would be 10 to 15 text view fields that will display the corresponding column values for that row.
Again, I admire your career and hope to see more articles from you.
Regards,
Julian
Jbeerdev Nov 25, 2009 4:43 AM
English
One last thing. Even my mother language is Spanish, I would like you to write in English. This way, people from other places can read the problems and maybe help you in some way.

thanks to all.
Jbeerdev Nov 25, 2009 4:17 AM
RE: Working With The Android Source Code
Buenas Julián.

Gracias! y espero que te sirvan los artículos que escribo para avanzar en Android.

El programa que comentas parece bastante fácil. Solo tener en una base de datos una información sobre las vigas y por pantalla introducir un valor que hará búsquedas en BBDD. ¿No es así?
Cierto que tengo que escribir sobre una aplicación que acceda a una base de datos y tal. Lo tengo pendiente!!

Un saludo.
Julian Varga Nov 25, 2009 1:13 AM
Gracias por tu ayuda
Vi tu pagina web personal y por eso se que hablas espaniol. Solo queria agradecerte por tus articulos. Son muy buenos, aunque todavia un poco avanzados para mi conocimiento. Recien empiezo con Android y la unica experiencia que tengo en programacion es un poco de fortran y alguno que otro programita de VB para Excel. Mi plan es bien simple y por eso me manengo con esperanzas de poder hacerlo. Quiero hacer un programa para mi telefono en el cual ponga el tamanio de una viga (por ejemplo W14x90) y me de todos los datos que tengo sobre eso. Lo tengo hecho en Excel y funciona bien, pero creo que es una buena manera de empezar en el mundo de la programacion de celulares.
Por ahora sigo buscando tutorials de database en Android, asique esperare a que hagas algun articulo mas detallado sobre database. Mientras intentare aprender un poco mas javascript, xml, y SQLite... Gracias y felicitaciones.
Jbeerdev Sep 27, 2009 6:09 AM
compiled andorid-source-code on mobile
Hi Joshua.

Well, first off all, you need yout phone to be rooted. You need to have privileges in your phone to do what you want to do. Where did you get the phone?

I have never compiled the android source code, but I have worked a bit with the images. Yesterday I managed to put other image in my HTC Magic Phone. Its easy if you have root.

If you want to know more, I will be very pleased in explaining you how to do this. Please write me to my personal email. Its easier and faster.

jbeerbros (at) gmail.com
Joshua Sep 27, 2009 5:22 AM
compiled andorid-source-code on mobile
Hi Jbeer,

do you know how to bring the compiled android-source-code like system.img, ramdisk.img ...etc on a mobile (Samsung Galaxy) ?

The point is I would like to download the android-source-code and then run "make". After that I would like to flash my mobile Samsung-Galaxy with the compiled code.

I copied the system.img, userdata.img to my mobile but I doesn't work. It ends up in a loop with the andorid-Logon-Screen.


Do you habe any idea how to manage this ?

Thanks,
Joshua
 
blog comments powered by Disqus
Email to a friend