wuntee
wuntee

Reputation: 12470

Android adding external libraries to project

I have a project that I would like to add external libraries to (and have them packaged with the application) but I am not sure it is happening. I read on this link:

https://developer.android.com/guide/appendix/faq/commontasks.html

how to, but they do not show up in any of the /data/data/project directories. Does anyone know how I can confirm that the libraries were in fact added to the project for use at runtime? Thanks.

Upvotes: 3

Views: 10962

Answers (3)

Cyberycon
Cyberycon

Reputation: 61

Be warned - external libraries (which are compiled against some version or other of the libraries in a Java JDK) may sometimes have problems when running under android. This is because the Dalvik runtime has its own Java framework libraries, which provide most (but not all) of the Java APIs in the standard JDK Java framework libraries.

You should really recompile any external library against the android libraries so that you can see any missing APIs at compile time - and fix the issues there and then. Otherwise you run the risk of runtime errors under Dalvik when you call the external library from your Android app. See http://geekswithblogs.net/cyberycon/archive/2011/05/17/using-external-libraries-with-android.aspx for more details.

Upvotes: 0

Maksim Golivkin
Maksim Golivkin

Reputation: 571

You can also place jar under one of your source folders (perhaps creating special "libs" one) and adding it to build path.

Upvotes: 0

Jim Blackler
Jim Blackler

Reputation: 23169

If you include jars as External Jars under your project's Java Build Path, then the classes will be converted to Dalvik format and be made available in your project's classes.dex file, packaged into the .apk.

To confirm they are available, attempt to use something from the jar (Eclipse should suggest the relevant import when you first supply a class name) build and run the app and see if it works? If it works in development (e.g. from 'run' in Eclipse) then it will also work when the app is built in release and distributed as an APK.

Upvotes: 3

Related Questions