现在的位置: 首页 > 综合 > 正文

Android: How to download the latest zip Android Source Code easily and using it in Intellij

2013年06月05日 ⁄ 综合 ⁄ 共 6070字 ⁄ 字号 评论关闭

http://geekycoder.wordpress.com/2009/07/03/how-to-download-latest-zip-android-source-code-and-using-it-in-intellij/

That’s definitely true for most developers using Windows as the main development platform and will want to get the latest Android Source code without installing any prerequisite software (Cygwin,
repo, git etc) to obtain the latest source code, and hence the fastest way to do so is to obtain the zip Android Source code uploaded by some kind souls. However, it is always best not to depend on someone else in the long run and therefore it will be beneficial
to learn how to obtain the latest source code. Although it is unnecessary to periodically getting the latest entire source code, it is good to know that one can easily obtain the latest source code just as easy as saving a file (albeit with much patience)
. In addition, the source code may even more valuable if it can be easily accessible in the IDE. So the objectives for this post is

This post will split into two main sections: Downloading
the Source
 Code andConfiguring
the Source Code for use in Intellij
.

Android: How to download the latest zip Android Source Code easily and using it in Intellij

This is a follow-up to my post: Android:
Zip download of Cupcake Android v1.5 source code

There is a popular quote which says

imageGive
a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime.

That’s definitely true for most developers using Windows as the main development platform and will want to get the latest Android Source code without installing any prerequisite software (Cygwin,
repo, git etc) to obtain the latest source code, and hence the fastest way to do so is to obtain the zip Android Source code uploaded by some kind souls. However, it is always best not to depend on someone else in the long run and therefore it will be beneficial
to learn how to obtain the latest source code. Although it is unnecessary to periodically getting the latest entire source code, it is good to know that one can easily obtain the latest source code just as easy as saving a file (albeit with much patience)
. In addition, the source code may even more valuable if it can be easily accessible in the IDE. So the objectives for this post is

This post will split into two main sections: Downloading
the Source
 Code andConfiguring
the Source Code for use in Intellij
.

Downloading
the Source Code

imageIn
fact, this post takes the inspiration and information from the post “How
to explore android source code”
 by Satya Komatineni, author of the excellent book, Pro
Android
. Pro Android is a very informative book of its kind to discuss Android programming in depth and really deserve the suffix “Pro”. The same information presenting in his post is included in the book (exclude the part on Eclipse) under the topic Taking
Advantage of Android Source Code
.

I consider the post by Satya Komatineni as one of the best post for Android development because it discuss on downloading/exploring on the source code of Android and configuring it for use in Eclipse.

 

Isn’t anyone happy that he can just download the latest source code by just entering the URL in the browser or clicking on the following link ?

image File:
base-HEAD.tar.gz (30mb)
 

http://git.source.android.com/?p=platform/frameworks/base.git;a=snapshot;h=HEAD;sf=tgz

How cool is that ? Perhaps it seems like old news for Android Veteran, but for many newbies that just step into the world of Android, it seems like a great news. In fact, this URL is mentioned in many blog comment and discussion forum but not frequently found
in posts (Hence it is one reason for this post). But be warned that the 30mb download does require some patience as it does not support download accelerator and the speed is average 15kbps.

Content
of the file

The right side contains the package under android directory.

 image

Or
another alternative ?

But for those who are impatient and rather just need the source code equivalent of android.jar, you just download the following 2mb source code jar file using Download Accelerator.  Essentially the source jar file contains those source from the directory <base\core\java
& base\graphics>. However, do take note that the android.jar file bundled with the Android SDK contains only subset of class files. There are some classes stripped off from android.jar.

image File:
android15_src.zip (3mb)

 

FAQ
of the Source Code

Is
the downloaded source code (base-HEAD.tar.gz file)
compliable?

NO. The source only contains the subset of the full source that required for successful compilation. Basically it contains the source of those class that is accessible from your IDE (through auto-completion etc) using android.jar that
come with the SDK. For example, sources such as those from package android.telephony and third-party library are missing (Yes, clearly missing from the download, not that they locate in other directory).

Attempt to compile the source in Intellij results in the following errors

image

 

Will
IDE display the source code that is included in source code directory/Jar file (android15_src.zip 
file) but which its class equivalent is not in android.jar ?

NO. It makes sense that IDE only recognizes the classes in a library (after all it is the binary library that get run, not the source code) and then from the class, attempt to find its source equivalent from the classpath, and not vice versa.  This unfortunately
means that the IDE is unable to find those source of class that is been intentionally stripped off in android.jar (properly to avoid been .

 

Configuring
Android Source Code for use in Intellij

imageFor
Android development, you have to use the latestIntellij
9 M1 (beta) release (download here)
  . The latest working Android plug-in is incompatible with Intellij 8.XXX. It appears that Android support is only available in Intellij 9 ultimately (?). For those who yet to try on Intellij, please do so otherwise
you might just miss out the one of the best things in the software development world.

Remember too to update to latest Android plugin (v0.9.3) as the one in M1 is the old version. The new version is much more robust and work flawlessly.

 

Intellij makes it so easy to add source code directory or zip/jar files for Java library. The following video shows how easy to add Android source code support in Intellij. 

 image

Use the android.jar from either android-1.1 or android-1.5 directory.

 

The most important step to take note is that android.jar
must be re-added
 as a library even though the project already include the Android module, otherwise Intellij will not be able to use the source code.

The following video shows

1) Creating a new Android project (It is here that you specify the Android module)

2) Creating library and adding android15_src.zip for
use

3) Navigate the Android source by cntrl+click on Android class name.

 

Note that it is useless to specify the Sources under [Configure Module Library] screen because the Sources will never be saved no matter how (Is this a bug ?). It is because of this reason that the aforementioned step is required.

image

 

That’s
it. Enjoy your Android Application development as much as I do !

抱歉!评论已关闭.