Logo Icon Logo
A Crowd-sourced Cookbook on Writing Great Android® Apps
GitHub logo Twitter logo OReilly Book Cover Art
Referencing Libraries to Implement External FunctionalityBack to Android Cookbook Home | Up to Chapter: Getting Started

Author: Rachee Singh ('racheesingh')
In Published Edition? Yes
FormatLanguage: WikiFormat

Referencing Libraries to Implement External Functionality

Problem

You need to reference an external library in your Android source project

Solution

Obtain the JAR file for the library that you require, and add it to your project.

Discussion

As an example, you might require to use AndroidPlot, a library to plot charts and graphs in your application or use OpenStreetMaps. For this your application needs to reference these libraries.

ADT Plugin Version 17 or later:

You are done: Eclipse (and the standard Ant build process) will now add your Jar file to the project's classpath.

ADT Plugin Version 16 or earlier (legacy)

In Eclipse you need to specify the Jar file in your build path:

For future reference you should create a folder called "libs" (not lib) and store the Jar file there.

Now you will see a 'Referenced Libraries' directory appearing in your project. Within this directory the JARs that you added will appear.

An alternate approach is to create a 'lib' folder in your project, physically copy the Jar files there, and add them individually as above, but using "Add Jars". This way keeps everything in one place (especially if your project is shared by a version control system to others who might even use a different operating system and be unable to locate the external jars in the same place). However it does raise the burden of responsibility for license issues on the included jar files.

In either case, if you also build with Ant, be sure to update your build.xml file.

Whichever way you do it, it's pretty easy to add libraries to your project.

See Also

Download

The source code for this project is in the Android Cookbook repository, http://github.com/IanDarwin/Android-Cookbook-Examples/tree/master/AndroidPlot