Correctly import a third-party library into an Android project

Jul 5, 2014

Here’s how you correctly import a third-party java library into an existing android project.

To import the project:

  1. File->Import->General->Existing Projects into Workspace, Next
  2. Select root directory: /path/to/project
  3. Projects->Select All
  4. UNCHECK both “Copy projects into workspace” and “Add project to working sets”
  5. Finish

To add it as a library for another project, see this link from the Android dev site:

  1. In the Package Explorer, right-click the library project and select Properties.
  2. In the Properties window, select the “Android” properties group at left and locate the Library properties at right.
  3. Select the “is Library” checkbox and click Apply

To actually use it in your project:

  1. In the Package Explorer, right-click your project and select Properties.
  2. In the Properties window, select the “Android” properties group at left and locate the Library properties at right.
  3. Click on Add, select the library project you added above and click Ok

All the steps except for the last section were taken from this StackOverflow answer. The last section I discovered on my own.

If you don’t follow all the steps, you’ll get the following type of error:

 Android application unhandled exception: Could not find class 'X', referenced from method 'Y'

If the imported library adds new views, you’ll get the following type of error:

android.view.InflateException: Binary XML file: Error inflating class fragment