Android is an open platform and as with any other open source software, Android has also made available the source code for the operating system.

Attaching source

Things are bit different when it comes to viewing the android source code in Eclipse IDE. With Java, when we download the JDK, the source code is also shipped and is present as src.zip file inside the JDK installation directory.

Using SDK Manager

With Android, we install the SDK using SDK manager and within the SDK manager, there is an option for downloading the source code for each API level. Remember that when using SDK manager to download the source code, the java files are download in exploded mode and not in the form of zip or jar. However you can create a zip file from any of the API level source code and attach it in Eclipse IDE (the steps for this are present at the end of this article)

Automatic install by using Eclipse plugin

Another easy to view the source code for Android class files is to use the Android Sources Eclipse plugin. The steps to install this plugin are given on the plugin page. An easy option to install and configure this plugin is to search for “Android sources” in the Eclipse Marketplace and click the Install button. The screenshot for this is shown below:

android-sources

Install Manually

We can also download the source code for any API level from the official android website. The steps given on the Android website describe how to use Git to download a copy of particular version:

Downloading the Source Tree

The GitHub page for android source code is:

android-github

Troubleshooting

If you are stuck after downloading the source code from any of the above sources then you can see try the following solutions:

Open any java file in you project which has reference to any class/interface from Android API. Press Ctrl+Click on the API class/interface which will show the following:

androidclass

Click the “Attach Source” button and locate the android.zip source code file. The location of source code zip file will vary depending upon the method used to download the source code.

  • Plugin: If you downloaded the Eclipse sources plugin then the source code file shall be present in the plugins folder of Eclipse. ($Eclipse/plugins/com.android.ide.eclipse.source…..)
  • SDK manager: If using SDK manager then the source shall need to be bundled into a zip file. Go to C:\Program Files (x86)\Android\android-sdk\sources. Right click on any of the API level folder and zip it using any zip utility. You need to provide the path to this zip file from the Browse option when you clicked on “Attach Source” button.
  • Github and repo: We didn’t get a chance to attach the source code downloaded using repo utility which downloads the code hosted on github. For guiding our readers, if the download is a zip/jar file then you can specify the file location else create a zip file containing the source code folders and files and use the same with Eclipse.

After attaching the source code in any of the above manner, Eclipse shall show the code as follows:

anroid activity

References

1. Android open source project
2. adt-addons

Related Posts

Attach android source code in eclipse admin Android
Android is an open platform and as with any other open source software, Android has also made available the source code for the operating system. 1. Attaching source 1.1. Using SDK Manager 1.2. Automatic install by using Eclipse plugin 1.3. Install Manually 2. Troubleshooting 3. References Attaching source Things are bit different when it comes to viewing...
Android is an open platform and as with any other open source software, Android has also made available the source code for the operating system. <div id="toc"> 1. <a href="#attachingsource">Attaching source</a> 1.1. <a href="#sdkmanager">Using SDK Manager</a> 1.2. <a href="#eclipseplugin">Automatic install by using Eclipse plugin</a> 1.3. <a href="#installmanually">Install Manually</a> 2. <a href="#troubleshooting">Troubleshooting</a> 3. <a href="#references">References</a> </div> <a name="attachingsource"></a> <h1>Attaching source</h1> Things are bit different when it comes to viewing the <strong>android source code</strong> in Eclipse IDE. With Java, when we download the JDK, the source code is also shipped and is present as src.zip file inside the JDK installation directory. <a name="sdkmanager"></a> <h2>Using SDK Manager</h2> With Android, we install the SDK using SDK manager and within the <a href="http://www.javaexperience.com/10-easy-steps-to-install-android-emulator-in-windows/" title="10 Easy steps to install Android emulator in windows" target="_blank">SDK manager</a>, there is an option for downloading the source code for each API level. Remember that when using SDK manager to download the source code, the java files are download in exploded mode and not in the form of zip or jar. However you can create a zip file from any of the API level source code and attach it in Eclipse IDE (the steps for this are present at the end of this article) <a name="eclipseplugin"></a> <h2>Automatic install by using Eclipse plugin</h2> Another easy to view the source code for Android class files is to use the <a href="http://code.google.com/p/adt-addons/" target="_blank">Android Sources Eclipse plugin</a>. The steps to install this plugin are given on the plugin page. An easy option to install and configure this plugin is to search for "Android sources" in the Eclipse Marketplace and click the Install button. The screenshot for this is shown below: <img src="http://www.javaexperience.com/wp-content/uploads/2013/03/android-sources.png" alt="android-sources" width="567" height="450" class="alignnone size-full wp-image-2466" /> <a name="installmanually"></a> <h2>Install Manually</h2> We can also download the source code for any API level from the official android website. The steps given on the Android website describe how to use Git to download a copy of particular version: <a href="http://source.android.com/source/downloading.html" target="_blank">Downloading the Source Tree</a> The <strong>GitHub page for android source</strong> code is: <a href="https://github.com/android" target="_blank">android-github</a> <a name="troubleshooting"></a> <h1>Troubleshooting</h1> If you are stuck after downloading the source code from any of the above sources then you can see try the following solutions: Open any java file in you project which has reference to any class/interface from Android API. Press Ctrl+Click on the API class/interface which will show the following: <img src="http://www.javaexperience.com/wp-content/uploads/2013/03/androidclass.png" alt="androidclass" width="338" height="399" class="alignnone size-full wp-image-2467" /> Click the "Attach Source" button and locate the android.zip source code file. The location of source code zip file will vary depending upon the method used to download the source code. <ul> <li><strong>Plugin:</strong> If you downloaded the Eclipse sources plugin then the source code file shall be present in the plugins folder of Eclipse. ($Eclipse/plugins/com.android.ide.eclipse.source.....)</li> <li><strong>SDK manager:</strong> If using SDK manager then the source shall need to be bundled into a zip file. Go to C:\Program Files (x86)\Android\android-sdk\sources. Right click on any of the API level folder and zip it using any zip utility. You need to provide the path to this zip file from the Browse option when you clicked on "Attach Source" button.</li> <li><strong>Github and repo:</strong> We didn't get a chance to attach the source code downloaded using repo utility which downloads the code hosted on github. For guiding our readers, if the download is a zip/jar file then you can specify the file location else create a zip file containing the source code folders and files and use the same with Eclipse.</li> </ul> After attaching the source code in any of the above manner, Eclipse shall show the code as follows: <img src="http://www.javaexperience.com/wp-content/uploads/2013/03/anroid-activity.png" alt="anroid activity" width="399" height="531" class="alignnone size-full wp-image-2471" /> <a name="references"></a> <h1>References</h1> 1. <a href="http://source.android.com/" target="_blank">Android open source project</a> 2. <a href="http://code.google.com/p/adt-addons/" target="_blank">adt-addons</a>
Android ImageSwitcher example
Android Activity example, How activity works in android application
The following two tabs change content below.
I run this blog with lots of passion. In this website, you will find tutorials on Core Java, Spring, Struts, Web Applications, Portals and Database. Please support me and the website by sharing the posts on your facebook / twitter. You can tap the share button at the top of each post. Thanks for the support.

Latest posts by admin (see all)

Comments

comments