662

Where can I browse the source code for any Android Open Source Project (AOSP) application (for example the Contacts application)? Is the only way to clone the entire source repository for all of AOSP?

Ryan M
  • 18,333
  • 31
  • 67
  • 74
Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622
  • 5
    You can always use this plugin for Eclipse to view android source: http://www.androidpolice.com/2011/12/22/gold-for-android-developers-add-aosp-source-code-to-eclipse-with-the-android-sources-plugin/ – Kalimah Jan 14 '12 at 10:57
  • 22
    I cant find Android API source at Google code search anymore. Maybe http://grepcode.com/project/repository.grepcode.com/java/ext/com.google.android/android/ is helpful. – xtr Jan 18 '12 at 14:45
  • @xtr, that's exactly the one I have recently found and was using. They [shut down Google Code Search](https://groups.google.com/group/google-code-search/browse_thread/thread/fa2e2908c47df068) but provided links to a few other resources at that link. – hotshot309 Jan 23 '12 at 16:52
  • Source code for all Android versions is here: https://android.googlesource.com/platform/packages/apps/Contacts.git/+/kitkat-release – zyamys Apr 03 '14 at 05:23
  • Can anyone find the source code for android.support.v7.widget.Toolbar? I have looked through multiple answers but have had no success finding the source code for this class. – Brendan Weinstein Nov 03 '14 at 20:40
  • You can go to http://androidxref.com/ and search for whatever you want. – Luander Jan 11 '16 at 16:03
  • You can get and browse the android source here : https://zgrepcode.com/android/ with IDE experience. – Amandeep Singh Feb 06 '19 at 18:21

7 Answers7

335

Everything is mirrored on omapzoom.org. Some of the code is also mirrored on github.

Contacts is here for example.

Since December 2019, you can use the new official public code search tool for AOSP: cs.android.com. There's also the Android official source browser (based on Gitiles) has a web view of many of the different parts that make up android. Some of the projects (such as Kernel) have been removed and it now only points you to clonable git repositories.

To get all the code locally, you can use the repo helper program, or you can just clone individual repositories.

And others:

jajube
  • 319
  • 2
  • 5
richq
  • 55,548
  • 20
  • 150
  • 144
  • 3
    It seems it is not available anymore – Eduardo Sep 05 '11 at 12:00
  • 1
    @Eduardo - it is a temporary thing due to the recent hack on kernel.org while they verify the repositories. – richq Sep 06 '11 at 06:30
  • 1
    It's still not available over a month later – Jim Wallace Oct 19 '11 at 00:43
  • @Jim kinda worrying - kernel.org is back, but the android repos are not. Maybe they're waiting for the icecream-sandwich open sourcing! – richq Oct 19 '11 at 10:04
  • 20
    It seems they killed off `android.git.kernel.org` definitively. It now redirects to `developer.android.com` page telling you how to download the sources, which refers to `android.googlesource.com`, but that does not seem to provide online browsing, only download. The github mirror is still there, but does not seem to be updated. – Jan Hudec Nov 11 '11 at 12:35
  • 1
    Indeed, the github mirror is old. Pull source like so: `git clone https://android.googlesource.com/platform/frameworks/base.git` – Bryan Denny Dec 06 '11 at 22:23
  • 4
    As of Dec 10 2011, the GitHub mirror seems to be updated real time. I can see commits which were made a few hours back. – HRJ Dec 10 '11 at 05:20
  • The github repo is incomplete. Today I can't see the libcore project for example. http://git.omapzoom.org/ has everything. – Jesse Wilson Apr 03 '12 at 14:13
  • 1
    @Jesse updated with the link, that is great. The other day I was looking for the platform/sdk and couldn't find it anywhere online. – richq Apr 03 '12 at 14:16
  • Looks like a lot of code is available at: http://code.metager.de/source/xref/android/ – Neil Townsend May 21 '13 at 16:14
  • 1
    How do I make the code I get from those repositories work? I've tried to import them and found so many compilation errors (more than 1000)... – android developer Jan 31 '14 at 08:14
  • 5
    There is now https://cs.android.com – tgeng Dec 10 '19 at 23:41
68

2020: The official AOSP code search https://cs.android.com/


You can view the source code through http://developer.android.com, when you're reading the API there will be a link to the matching source code on GitHub, you just need to add the Android SDK Reference Search Plugin on Chrome.

I blogged about it here:
http://blog.blundellapps.com/add-source-code-links-to-android-apis/

enter image description here

Blundell
  • 75,855
  • 30
  • 208
  • 233
44

I stumbled across Android XRef the other day and found it useful, especially since it is backed by OpenGrok which offers insanely awesome and blindingly fast search.

scorpiodawg
  • 5,612
  • 3
  • 42
  • 62
  • It appears to be missing some files. For example, the [Android 4.3 CDD](https://static.googleusercontent.com/external_content/untrusted_dlcp/source.android.com/en/us/compatibility/android-4.3-cdd.pdf) specifically calls out /data/misc/sms/codes.xml on page 34. A search of the path results in not found, and a search of the file only returns near hits. – jww Aug 02 '13 at 05:30
  • @noloader: I think this file is expected to be put on specific device implementations, but does not exist in AOSP. See here for the AOSP code that gets activated when such a file is put on the device: http://androidxref.com/4.3_r2.1/xref/frameworks/base/services/java/com/android/server/updates/SmsShortCodesInstallReceiver.java – scorpiodawg Aug 07 '13 at 05:53
  • Yes it is insanely fast but I dont see kernel folder in the source code. Any reason for this? – Sandeep Sep 19 '13 at 09:00
  • Not sure who's idea it was to close this good question as off-topic. Android XRef seems to be not updated anymore, you can get the same and even better now on http://aosp.opersys.com/ – k_o_ Jan 12 '20 at 18:25
6

I've found a way to get only the Contacts application:

git clone https://android.googlesource.com/platform/packages/apps/Contacts

which is good enough for me for now, but doesn't answer the question of browsing the code on the web.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622
  • One can indeed get individual packages by pulling their git repositories from a currently active URL. However, this is mostly useful for study - even things that seem like they *should be* SDK-based ordinary applications typically have dependencies elsewhere in AOSP and so will not build via the SDK, but rather only in the context of a larger build of a more complete AOSP checkout. – Chris Stratton Jun 04 '16 at 18:03
1

You can browse Android SDK samples from your smartphone using "Code Search": https://market.android.com/details?id=sqwady.codesearch

Eyal
  • 516
  • 6
  • 9
1

This eclipse plugin allows for inline source viewing and even stepping inside the Android source code:

http://code.google.com/p/adt-addons/

(edit: specifically the "Android Sources" plugin: http://adt-addons.googlecode.com/svn/trunk/source/com.android.ide.eclipse.source.update/)

Rangel Reale
  • 698
  • 6
  • 7
0

gitweb will allow you to browse through the code (and changes) via a browser.

http://git.or.cz/gitwiki/Gitweb

(Don't know if someone has already setup a public gitweb for Android, but it's probably not too hard.)

Peter Boughton
  • 110,170
  • 32
  • 120
  • 176