Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get source code for android.jar

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

like image 863
Li Haoyi Avatar asked Aug 08 '13 12:08

Li Haoyi


People also ask

Where can I get source code for Android?

The Android source tree is located in a Git repository hosted by Google. The Git repository includes metadata for the Android source, including changes to the source and when the changes were made. This page describes how to download the source tree for a specific Android code line.

How can I see the code in a jar file?

The JD-GUI is a nice open-source GUI utility to explore Java source code decompiled by the Java decompiler JD-Core. When we see the main window of JD-GUI, we can either open our JAR file by navigating the menu “File -> Open File…” or just drag-and-drop the JAR file in the window.

Can we extract code from jar file?

Jar files are archive files that contains of a lot of different java classes (files). You can use winzip/winrar to open the jar files and you can see those java classes in jar files. Typically you can use a Java decompiler to decompile the class file and look into the source code.


3 Answers

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.

like image 69
CommonsWare Avatar answered Sep 30 '22 21:09

CommonsWare


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

like image 23
crocboy Avatar answered Sep 30 '22 20:09

crocboy


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.

like image 36
Phil Avatar answered Sep 30 '22 19:09

Phil