Adding an External Library (.jar) using Eclipse 


July 21, 2011 12:58:59    Last update: July 21, 2011 13:02:17
From Android Developers:

You can use a third party JAR in your application by adding it to your Eclipse project as follows:
  1. In the Package Explorer panel, right-click on your project and select Properties.
  2. Select Java Build Path, then the tab Libraries.
  3. Press the Add External JARs... button and select the JAR file.

Alternatively, if you want to include third party JARs with your package, create a new directory for them within your project and select Add Library... instead.

It is not necessary to put external JARs in the assets folder.

Apparently, this is not working for me! I added a libs folder, put the external jar in libs. The project built fine, but the APK does not include the external jar, giving me ClassNotFound error at runtime. Then, I added the jar to the assets folder and the external jar got packaged with the APK, but still ClassNotFound!

If I add the libs folder with Add Class Folder..., then the external jar is included twice in the resulting APK: once in the classes.dex file, and once as the original jar at the root path!

The ADT version was: 12.0.0.v201106281929-138431.
Share |
| Comment  | Tags