Here’s how you correctly import a third-party java library into an existing android project.
To import the project:
- File->Import->General->Existing Projects into Workspace, Next
- Select root directory: /path/to/project
- Projects->Select All
- UNCHECK both “Copy projects into workspace” and “Add project to working sets”
- Finish
To add it as a library for another project, see this link from the Android dev site:
- In the Package Explorer, right-click the library project and select Properties.
- In the Properties window, select the “Android” properties group at left and locate the Library properties at right.
- Select the “is Library” checkbox and click Apply
To actually use it in your project:
- In the Package Explorer, right-click your project and select Properties.
- In the Properties window, select the “Android” properties group at left and locate the Library properties at right.
- 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