Android platform consists of millions of lines of C, C++ and Java code. I am part of a team building an embedded device that uses Android as OS. One of the challenges we have often faced as developers is how to navigate Android platform code (aka AOSP) easily.
Most IDEs like Eclipse, IntelliJ provide shortcuts to do this if the source code is managed through a project. Using Eclipse page on AOSP site describes importing the source code into Eclipse. That doesn't work as expected. Following those instructions broke AOSP build because of artifacts left behind by the Eclipse project. This post describes a way to accomplish this without breaking AOSP build.
Most IDEs like Eclipse, IntelliJ provide shortcuts to do this if the source code is managed through a project. Using Eclipse page on AOSP site describes importing the source code into Eclipse. That doesn't work as expected. Following those instructions broke AOSP build because of artifacts left behind by the Eclipse project. This post describes a way to accomplish this without breaking AOSP build.
Lets assume the AOSP sources are located at /home/videoguy/platform/mars folder. This is the top level folder under which you should see frameworks, build, kernel etc sub directories. This folder is referred as <aosproot> in the sections below. To keep this folder clean from IDE artifacts, we need to create a shadow folder. Lets assume the shadow folder is located at
/home/videoguy/platform/ide/mars
. This folder is referred as<shadowroot> below.
- Open a terminal window and change directory to <aosproot>.
Build the AOSP platform the way you normally do. You should see <aosproot>/outwith build artifacts after this. If you haven't created <shadowroot> yet, please create it before continuing. The directory structure should look like below.
- Change directory to <shadowroot>. Invoke lndir command like below at command prompt.
$lndir ../../mars
This will make the shadow directory mimic the structure of <aosproot> with symlinks pointing to files under <aosproot>. If you make changes to the files from Eclipse, the files under <aosproot> get changed and vice versa. - Copy development/ide/eclipse/.classpath to <shadowroot>. The following command will do if invoked from <shadowroot> folder.
$cp development/ide/eclipse/.classpath . - Launch Eclipse. This procedure was tested using Kepler version of Eclipse running on UBuntu. Make sure you have 512MB of heap space set aside. On my box, eclipse is launched like below.
$eclipse -vmargs -Xmx512M -Xms256M -XX:MaxPermSize=256M
- Create a new Java Project. For this, Choose File->New->Java Project or right click in "Package Explorer" space and select "New->Java Project" menu item.
For "Project Name", enter "Android Platform".
Uncheck "Use default location" and browse and select <shadowroot> directory.
The new project dialog should look like below.
- Press "Next" button and wait. This step takes around 30 seconds.
- Press "Finish" and wait. This takes around 10-20 seconds. You might see "Eclipse running out of memory" error or "GC limit reached" error. If eclipse prompts you to close workbench, please do so. You can ignore these errors.
- Close Eclipse and Relaunch. You should see "Android Platform" project like below when expanded.
This is a great way to edit platform Java code using IDE with source completion and other goodies.
Please keep in mind that this project is meant for browsing, editing and debugging Framework java code. It is not meant for building AOSP from eclipse. Please use a terminal window to make builds manually.
Please keep in mind that this project is meant for browsing, editing and debugging Framework java code. It is not meant for building AOSP from eclipse. Please use a terminal window to make builds manually.
In a future posting, I will show you how to debug framework service like window manager using this project.