6

I'm not actually working on android devices, but I'd like to use the android java std lib for a project of mine. I'm extracting the android java std lib from the android ADT here:

http://developer.android.com/sdk/index.html

After unzipping the bundle, it's in

adt-bundle-windows-x86_64-20130729\sdk\platforms\android-18\android.jar

However, when I open this up in Intellij, it doesn't show any source code: all methods are just labelled as "compiled code"

Is there any way to get the source code (in a jar or otherwise) for the android.jar so I can hook it up to the IDE so I can nicely browse the source code of the standard library? I've dug through the sdk download bundle and haven't found anything.

-Haoyi

Li Haoyi
  • 15,330
  • 17
  • 80
  • 137
  • when i open the andorid.jar with VIM it shows me 10k line of code! mostly they are paths for xmls and java-classes. – bofredo Aug 08 '13 at 13:01
  • Just out of curiosity, what are you using android for that doesn't involve android devices? – supersam654 Aug 08 '13 at 13:03
  • 1
    @supersam654 I want to use it as a more-or-less compatible, much-less-bloated java class library for my Metascala JVM – Li Haoyi Aug 08 '13 at 13:09
  • possible duplicate of http://stackoverflow.com/questions/5107187/extract-source-code-from-jar-file – Phil Aug 08 '13 at 13:16

4 Answers4

4

but I'd like to use the android java std lib for a project of mine

I have no idea why you think that would work, any more than trying to use a Windows DLL on Linux.

Is there any way to get the source code (in a jar or otherwise) for the android.jar so I can hook it up to the IDE so I can nicely browse the source code of the standard library?

The source code for Android is at the Android Open Source Project. The source code for the android.jar is mostly in the platform_frameworks_base repo (GitHub mirror), but the JAR is really an output of a firmware build.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • That looks like what I want; but one question: do you have any idea where the java.lang.*, java.util.*, etc. classes are in that repo? I'm digging through right now and haven't found anything – Li Haoyi Aug 08 '13 at 13:13
  • @LiHaoyi: "do you have any idea where the java.lang.*, java.util.*, etc. classes are in that repo?" -- well, since you already have those in your JVM, I'm not quite clear on what you need Android's for. Regardless, for individual classes, it's simpler for you to install Roman Nurik's Chrome extension, which adds "view source" links to each developer.android.com JavaDocs page. For example, that extension shows the definition of `String` here: https://android.googlesource.com/platform/libcore/+/refs/heads/master/luni/src/main/java/java/lang/String.java – CommonsWare Aug 08 '13 at 13:21
3

In your Android SDK root directory, go to the sources folder. Here you will find the source files for the different platforms you have downloaded.

Note: This gives you the Java code for Android libraries such as Activity

crocboy
  • 2,887
  • 2
  • 22
  • 25
  • Thank you ! I choose download source in my "Android SDK Manager",But I can't find it where it is when downloading is done. Now I find it ! – Eddy Mar 12 '15 at 03:18
1

Unpacking the jar is way more than you need to worry about. Android is open source, so you can get everything you need online. To start, you can browse most of the source on Android's GitHub account, or download the source tree on the Android Open Source Project website. You can also view most (if not all) sources on GrepCode.

If you really want to go through the trouble of extracting the jar and decompiling the source, you can use JD-GUI.

Phil
  • 35,852
  • 23
  • 123
  • 164
  • the link [GrepCode](http://grepcode.com/project/repository.grepcode.com/java/ext/com.google.android/android) only contains andoid.jar up to 5.1.1. Is there a way of getting jar of android version-6 ? – Malinda Nov 06 '17 at 10:47
0

As you use eclipse, use

jadclipse

which extrach any jar that in eclipse, u can view any source code with out download and also without internet. It has also export source code, As a developer It help u most times. :-> link to download

Selvaraj
  • 714
  • 2
  • 6
  • 14