How to get source code for android.jar - java

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

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.

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

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.

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

Related

Convert a whole android package to jar file in eclipse

i know we can convert a java class file into a jar file , but i want to know , is there any way to convert a whole Android Package into a jar file or another format , so i can use them in another project ?
and if with any way we can convert it , and the main app has some permissions , are they added to second app or i must add them in second app manifest ?
You can create an Android Archive Library i.e. an AAR file (*.aar) if you make your project a library. As far as I know a JAR file cannot contain all the Android specific components of the project. You can find a very brief JAR/AAR comparison in this discussion.
You can have a look at these tutorials by Vogella and Android By Code for creating such a library and you may find relevant Stackoverflow discussions with the "aar" tag. But as this is a rather new feature and support in Android Studio (or Eclipse ADT) has improved from version to version some of the older discussion might not be up-to-date anymore.
The permissions specified in the library's manifest will apply to the library code even in the app. that is using the library. Commonsware has explained the manifest aspect in more detail.
Firstly, you must go in Eclipse, to File -> Export -> Java (jar file) -> and there you select the package you want to export as a .jar file.
Concerning your second question, you must add the permissions again to the second application.

"Line not available" in android debugging

I have an Android library source code and .jar archive for that library. I also have and Android app that makes use of that library. My library source code and Android app are in the same Eclipse workspace. So, I added .jar archive to build path of the Android app, and attached source code to that .jar archive.
I am able to look inside the functions I call in my app, but when I am debugging, I can not step through the functions from the library that I am calling. In the debugger it says "line: not available".
How can I make it so that I can step through the code in the library? I know that in the Java compiler settings for the Android library, I have to check the box on "Add line number attributed to generated class files", which I already did for both Android app and Android library.
Did I miss something? Why do I still get "line: not available" message in debugger and can't step through the code from library?
Both library and app are compiled with Java 1.6. Android app's build target is Android 5.1.1, and libraries' build target is Android 4.0.3 .
I actually figured it out. I was using .jar archive for this library, but this .jar archive wasn't generated by me and apparently did not allow for line numbers to be added to generated class files. I exported my own .jar archive, linked source code to .jar archive, and was able to debug the code without any issues.

How to create jar file from Android Library project

I have a Android library project need to convert this in to a jar file and use it on my Android project.like we are doing on Adds network integrations,Is there any way to achieve this?.
An Android project can't really fit into a .jar file, unless you just wanna use the compiled java files, which you would certainly have done it via a normal Java library project instead of a Android Library Project in first place.
Android Library Projects are packaged into aar files. Read more about it here: http://tools.android.com/tech-docs/new-build-system/aar-format and it is automatically handled by Gradle builds and late Android Maven scripts...this last one used to use a 'apklib' format which has been deprecated to be replaced by aar format. You can read more about it here: https://code.google.com/p/maven-android-plugin/wiki/ApkLib
I've done this before.
But, due to my requirements, i only needed implementation (no android specific resources). Although you can still include Android actual code (if the project you're going to use it in is also an Android project in which you can load the SDK which includes the classes you're exporting in the jar)
Now the .jar file that is automatically generated in the bin folder, will not allow you to do this because it includes all the Android's project resources (which is not understood in the Jar format). Therefore, you must exclude all except the src folder. Note : Make sure you also exclude the files in the root folder of the project (i.e, AndroidManifest.xml, etc .. )
In Eclipse : Project properties -> Export -> Jar -> (Include only src folder)
If you're project library includes native code ( NDK ), there is a few other workaround that you need to do to get it to work. If this is the case, comment below, i'll help you out.
Cheers

How to correctly build Jsoup.jar and export it to be used by Android APP

The current Jsoup release 1.7.3 has a known issue that it is using String.isEmpty() which is not supported by Android API Level 8.
I can see crash report of my app so I tried to fix this by change the source code of Jsoup and build my own jsoup.fix.jar. I test this jar with JAVA application and it worked fine on my PC.
I noticed that when I remove the original jsoup-1.7.3.jar from my project, there is errors complaining cannot find jsoup stuff, and the those errors are gone after I add the jsoup.fix.jar which seems to be good. I also check the JAVA build path and the exporting configurations, jsoup.fix.jar are all set as it should.
However, when I tried to run the APP on my Android devices, the APP crashed and saying it cannot find org.jsoup.Jsoup.
I checked the jsoup.fix.jar, opened it with JD-GUI and find the classes are all there, but I used my dex2jar to convert the classes.dex in my /bin directory, I cannot see nay org.jsoup stuff.
Just replace my jar file with the original jar will not have the same issue reproduced.
I also noticed that in my jar, the MANIFEST.MF file only have one line of content, but in the released jsoup-1.7.3.jar, the MANIFEST.MF contains a lot of content.
I am confused now, questions:
Am I doing wrong when build my own jar?
Why the APK still cannot include the jsoup pacakage even I configured it to do so?
Finally I found the reason might be the jar is exported from a JAVA project.
I have tried to create an Android project and copy the source files into it and then export another jar file, and it works!
Could anybody explain why?

Add android jar to eclipse

When I open the android jar I'm not able to see .java files , it shows .class files in it .
Please suggest me how to add android jar to eclipse.
Waiting for an early response.
If you want to check the java code of android you should better visit Andrdoid x-86 branch wesite and follow the instructions there.
But you can not see the java code by adding its JAR file in the eclipse project class path.

Categories

Resources