{infiniteZest}
// Articles. Tutorials. Utilities.
Home  |   Search  |   Login  
Categories Skip Navigation Links
New / All
AJAX
Apple
ASP.NET
.NET
Git
Google / Android
Python / IronPython
Miscellaneous
SQL Server
Jar-ing through the Android Library
Summary
This article looks at the contents of the android.jar file via the jar tool and others.
 
Table of Contents

The Graphical way

Figure 1. android.jar from an Android application

The JAR Way

The Help/Usage

Code Listing 1. The Usage output of jar

Table of contents

Code Listing 1. Listing of directories and files in android.jar

Verbose Table of Contents

Code Listing 2. Verbose Table of Contents

Getting directories and images from a jar file

Getting one image / one class from a jar file

Figure 2. The default Android application icon

 

The Graphical way

The file android.jar is the physical manifestation of all the functionality in Android SDK. The Android applications you develop will use the functionality available in this .jar (Java Archive) file.

The best and easiest way to look at the contents of the android.jar file will be to open it from the Package Explorer of Eclipse. If an Android application is created via the Android plugin, this android.jar will be automatically included in the application.

Figure 1. android.jar from an Android application

Figure 1. android.jar from an Android application

As you can see in Figure 1, the Android Library (as specified by android.jar) is in this Android application. This file is in the root of SDK directory (for example, ...\android-sdk_m5-rc15_windows).

By clicking through the various package nodes in Package Explorer, you can see the classes included in that package. You can also see the resources, like xml and png files (under the res package).

The JAR Way

The Java SDK (or JDK) includes a tool called jar (jar.exe on Windows). This tool gives a great command line way to look at the contents of a Java Archive file (.jar). This tool is in the bin directory of JDK (for example, in C:\Program Files\Java\jdk1.6.0_05\bin directory; so, make sure to include this directory in the PATH).

Following are some examples of using the JAR tool on android.jar and finding out what’s inside.

The Help/Usage

First let’s see the help/usage output that you get when you just type jar at the command prompt.

Code Listing 1. The Usage output of jar

D:\Test>jar
Usage: jar {ctxui}[vfm0Me] [jar-file] [manifest-file] [entry-point] [-C dir] files ...
Options:
    -c create new archive
    -t list table of contents for archive
    -x extract named (or all) files from archive
    -u update existing archive
    -v generate verbose output on standard output
    -f specify archive file name
    -m include manifest information from specified manifest file
    -e specify application entry point for stand-alone application
        bundled into an executable jar file
    -0 store only; use no ZIP compression
    -M do not create a manifest file for the entries
    -i generate index information for the specified jar files
    -C change to the specified directory and include the following file
If any file is a directory then it is processed recursively.
The manifest file name, the archive file name and the entry point name are
specified in the same order as the ’m’, ’f’ and ’e’ flags.

Example 1: to archive two class files into an archive called classes.jar:
       jar cvf classes.jar Foo.class Bar.class
Example 2: use an existing manifest file ’mymanifest’ and archive all the
           files in the foo/ directory into ’classes.jar’:
       jar cvfm classes.jar mymanifest -C foo/ .

Table of contents

In order to list the table of contents inside a jar file, use the switch ‘tf’. Here ‘t’ is for table of contents and f is for file. The android.jar (from m5-rc15) has 7012 files and directories. So, obviously, if you want to capture all those files, you can redirect the output to a file. In the example below, the output has been placed in android-table.txt file.

Code Listing 1. Listing of directories and files in android.jar

jar tf android.jar > android-table.txt


In the file:

AndroidManifest.xml
SQLite/
SQLite/Authorizer.class
SQLite/BlobR.class
SQLite/Blob.class
SQLite/BlobW.class
SQLite/BusyHandler.class
SQLite/Callback.class
SQLite/Constants.class
SQLite/Database.class
SQLite/Exception.class
SQLite/TableResult.class
SQLite/Function.class
SQLite/Trace.class
SQLite/Vm.class




<<7012 files and directories>>

The above listing will show you .class, .xml, and .png files. It’s interesting that those are the only kinds (just three) of files you would find in the entire android.jar Java Archive file. Of course, a huge bunch of them are simply .class files.

Needless to say, the .jar file provides an extraordinarily easy way to move all these files from one place to another. Here, in android.jar file, we have 7000+ files and they are all compressed into one under 10MB file. Moving one file is easier than moving thousands of files in several directories.

Verbose Table of Contents

To the above command, if you add the option ‘v’, then you will get a verbose table of contents. The extra information includes the size of the file, date, and full directory appended to each file.

Code Listing 2. Verbose Table of Contents

jar tvf android.jar > android-table-verbose.txt


In the file:

13480 Thu Feb 28 17:16:44 PST 2008 AndroidManifest.xml
     0 Thu Feb 28 17:11:20 PST 2008 SQLite/
   207 Thu Feb 28 17:11:20 PST 2008 SQLite/Authorizer.class
  1702 Thu Feb 28 17:11:20 PST 2008 SQLite/BlobR.class
   843 Thu Feb 28 17:11:20 PST 2008 SQLite/Blob.class
  1115 Thu Feb 28 17:11:20 PST 2008 SQLite/BlobW.class
   150 Thu Feb 28 17:11:20 PST 2008 SQLite/BusyHandler.class
   205 Thu Feb 28 17:11:20 PST 2008 SQLite/Callback.class
  2668 Thu Feb 28 17:11:20 PST 2008 SQLite/Constants.class
  7625 Thu Feb 28 17:11:20 PST 2008 SQLite/Database.class
   332 Thu Feb 28 17:11:20 PST 2008 SQLite/Exception.class
  1655 Thu Feb 28 17:11:20 PST 2008 SQLite/TableResult.class
   237 Thu Feb 28 17:11:20 PST 2008 SQLite/Function.class
   138 Thu Feb 28 17:11:20 PST 2008 SQLite/Trace.class
   581 Thu Feb 28 17:11:20 PST 2008 SQLite/Vm.class
  1765 Thu Feb 28 17:11:20 PST 2008 SQLite/Stmt.class
   143 Thu Feb 28 17:11:20 PST 2008 SQLite/ProgressHandler.class
   578 Thu Feb 28 17:11:20 PST 2008 SQLite/FunctionContext.class





Getting directories and images from a jar file

From the directory structure, we can see that the directory ‘res’ contains all the resources. Within res, the ‘drawable’ directories contain the actual .png files and the xml files that are drawable by the Android. Following example shows getting/extracting entire directories of files from a jar file.

jar xf android.jar res/drawable

The above command extracts all the directories under res that match drawable. So, you will get the directories drawable, drawable-finger, drawable-land-finger, and drawable-port-finger.

If you are using the above command from d:\test\android, then the directory res will be created underneath that directory. And the drawable directories will be under the res directory. These are the real extracted files.

The drawable directory has png files like button backgrounds, checkbox backgrounds, edit box backgrounds, battery levels, signal levels, and so on.

Getting one image / one class from a jar file

Getting one image / one file follows the same pattern. For example, the default Android icon you see on the device is called sym_def_app_icon.png. This is in the res/drawable directory.

Figure 2. The default Android application icon

Figure 2. The default Android application icon

To get the above file, simply extract file (xf) by specifying the full path:

jar xf android.jar res/drawable/sym_def_app_icon.png

Bookmark and Share This

More Articles With Similar Tags
icon-android-debug-toolbar.jpg
This article gives some quick pointers on how to start debugging an Android application, along with where to put the breakpoints and how to change the emulator sizes from within Eclipse.
icon-android-safari-browser-user-agent-string.jpg
This article talks about the basics of the browser (including the user agent string) used in the Android platform.
This article talks about various aspects of creating an SQLite database. It also uses Android SQLite shell as an example.
This article explains how to get pretty / nice output from the SQLite command line shell program.
icon-android-emulator-hvga-p-lunar-lander.jpg
See the images of various skins and screens of Android emulator with games (Lunar Lander and Snake) in them. Also shows how to change the skins of Android emulator while debugging your program.
About  Contact  Privacy Policy  Site Map