8

I want to add an external library to my Android Studio 1.0 project. The other answers at stackoverflow seem to be outdated. At least I can't find a "lib" folder in my project and don't know how to create one.

edit: As I was pointing out I am referring to the latest version of Android Studio. I assume there are some differences between this version and the one referred to. The shortcuts are not working and my folder structor varies a lot. I created a new HelloWorld project to verify it.

user1255102
  • 486
  • 4
  • 16

2 Answers2

2

In the module that want to use the jar, create a lib folder and place your jar in it.

In the module build.gradle file, add this in the dependencies group:

compile files('lib/my_jar.jar')
Gaëtan
  • 11,912
  • 7
  • 35
  • 45
  • I know it is a really stupid question, but how do I create a folder under the app directory from inside Android Studio? I am new to Android Studio and was not able to figure it out by my own. – user1255102 Dec 18 '14 at 19:31
  • 1
    The easiest way would be to do from your file explorer, not in Android Studio. You can do it in Android Studio, by switching to the "Project" view (on the left side of the screen, above the project tree, click on "Android" and select "Project"). Then you can create a folder by right-clicking on the appropriate folder. – Gaëtan Dec 18 '14 at 21:16
  • Thank you very much! It seems a little bit tricky to me. :-) – user1255102 Dec 19 '14 at 10:24
0

Create a directory named lib under the app directory. Then place your jar file there. Then make sure the line is present under dependencies section of build.gradle

 compile fileTree(dir: 'libs', include: ['*.jar'])

Sometimes, i just place the jar in the lib folder and right click on it and select Add as library.

Panther
  • 8,938
  • 3
  • 23
  • 34