Sez
Sez

Reputation: 1293

How to include external libs in Android source controlled project?

How should external libraries be included into Android projects?

I see this documentation from Google:

http://developer.android.com/tools/support-library/setup.html#libs-with-res

...which says they should be kept outside the source tree for the project, and referenced as dependencies.

The guide for Facebook libraries says the same thing:

https://developers.facebook.com/docs/android/getting-started/facebook-sdk-for-android/

What about when the project is going into source control, and will be worked on by multiple developers? Is it possible to be sure other developers will have the correct versions of libraries if they're not included in source control?

It seems as though it might be better to check in the whole tree of these external libraries under say an "external" folder in the project and then reference them as libraries from there? The above links don't say this is wrong, but is there any reason not to do that?

I could not find anything against this approach, but maybe my search skills are off.

Thanks!

Upvotes: 0

Views: 877

Answers (3)

Harshit Rathi
Harshit Rathi

Reputation: 1862

If you want to add jar file then copy your jar file and put in to libs folder, and if you want to add external library then import your library project go to project properties and select android tab and add external library with add button.

Upvotes: 0

flx
flx

Reputation: 14226

You have basically tree options (referring to git):

  1. Putting the source or binaries into your git repository.

  2. You can create/clone extra repositories and link these as submodule into your main repository.

  3. Use gradle/android-studio to maintain remote binary dependencies.

In my opinion, option 3. is the best. It speeds up build time and reduces the date saved in your internal repository. Referencing most open source projects, googles libraries and even the Facebook API is just a one liner in your build.gradle file.
For internal libraries or anything not uploaded to some maven repository, you can create a local maven repository and link that.
And in the end, you have the option 2. to create a library submodule within git and gradle to handle it efficiently.

If you want to stick to eclipse + ant, try 2. first. At least ant will work out of the box for building all things. Setting up eclipse is a bit more difficult but can be done.

Option 1. is easy to implement, but It might get messy at some point.

Upvotes: 1

Vijay Rajput
Vijay Rajput

Reputation: 1091

Copy jar file in android project libs forlder and right click on jar file and click on bulid path-> add to build path.

Upvotes: 0

Related Questions