I am new to Android Studio.
How can I add a few jar files in the External Libraries
below the < JDK > folder?
-
Please check this link : http://stackoverflow.com/questions/16588064/how-do-i-add-a-library-project-to-the-android-studio – Sayem Sep 04 '14 at 08:03
16 Answers
A late answer, although I thought of giving an in-depth answer to this question. This method is suitable for Android Studio 1.0.0 and above.
STEPS
- First switch your folder structure from Android to Project.
- Now search for the libs folder inside the app folder.
- Once you have pasted the .jar file inside libs folder. Right click on the jar file and at end click on Add as library. This will take care of adding compile files('libs/library_name.jar') in build.gradle [You don't have to manually enter this in your build file].
Now you can start using the library in your project.
-
5Yes, I found that now, if it is already added then that option will not show. – Shailendra Madda Nov 24 '17 at 06:28
Add your jar file to the folder app/libs
. Then right click the jar file and click "add as library".
If there is no libs
folder you can create it. Click on the combo box that says "Android", and change it to "Project"
From here, you can right click on "apps" in the directory tree and go to "New" => "Directory"
-
38If you can't find a lib folder, just click on the combobox that says "android" and choose "Project". (that button is on the top of the project explorer) – Gayan Weerakutti Apr 21 '15 at 14:28
-
4You can then expand your Project to find the "libs" folder or right click your project and make a new directory. You can then move the JAR file for your library into that directory using your OS file manager. (Thanks, @reversiblean for getting me started!) – Richard Jul 26 '15 at 17:21
-
+1 for @reversiblean's comment -- the default view is "Project Files" not "Project", and that view doesn't show the "app/libs" folder, but won't let you create it either. – Jules Jan 25 '17 at 02:57
Put your JAR in app/libs, and in app/build.gradle add in the dependencies
section:
implementation fileTree(dir: 'libs', include: ['*.jar'])
-
can I choose another/ My own path like "values\my_folder\myjar.jar" ??? because I am working on source code of android studio. – Sanket Prabhu Dec 21 '15 at 13:29
-
You just need to change the value of 'dir' (so replace 'libs' with whatever you need). – Gaëtan Jan 22 '16 at 07:55
-
1
-
1yes, Deepak is correct - 'compile' is deprecated...so just replace it with 'implementation' and it should work fine. – Mark May 31 '19 at 01:01
Create "libs" folder in app directory copy your jar file in libs folder right click on your jar file in Android Studio and Add As library... Then open build.gradle and add this:
dependencies {
implementation files('libs/your jar file.jar')
}

- 3,856
- 3
- 48
- 63

- 1,006
- 4
- 14
- 38
-
1`Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.` – Michael Nov 27 '18 at 16:49
Step 1: Download any JAR file for your Project.
Step 2: Copy .jar file and past in libs folder.
Step 3: Click on File > Project Structure >Select app > Dependencies
Step 4:
Step 5:
Step 6: After click Ok button then we can see the Dependencies add like this way:

- 1,296
- 1
- 11
- 24
-
5Out of date. Anyone have the solution for Android Studio 4.0? These interfaces no longer exist – Brian Reinhold Jul 28 '20 at 20:10
-
@BrianReinhold, yes. You can see easier ways here, for instance, @Enamul Haque. Inside `app` folder create `libs`, add a library there. Then in `app\build.gradle` write: `implementation files('libs/library_name.jar')` – CoolMind Feb 12 '21 at 19:02
In Android Studio version 3.0 or more I have used bellow like :
- Create libs to the app directory if not exist folder like
- Set
Project
view in upper left corner - Go to project
- Go to app
- click on apps->New->Directory
- name the folder libs
- paste the jar to the libs folder
- directory will look like bellow image
In build.gradle add these lines
// Add this line if was not added before. implementation fileTree(dir: 'libs', include: ['*.jar']) implementation files('libs/com.ibm.icu_3.4.4.1.jar')

- 26,736
- 15
- 188
- 224

- 4,789
- 1
- 37
- 50
Example with Parse jar...
Add jars to libs folder from Project view … create lib folder if not exists
Copy all jars there...
Add libs to gradle.... in build.gradle file :
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.android.support:design:23.0.0'
compile 'com.android.support:percent:23.0.0'
compile 'com.parse.bolts:bolts-android:1.+'
compile fileTree(dir: 'libs', include: 'Parse-*.jar’)
}
For add all jars of lib folder... change Parse-*.jar to *.jar

- 161
- 1
- 5
This is how you can add .jar
file in Android Studio 2.1.3.

- 1,615
- 2
- 22
- 25
-
(At least with AS 2.3) You can skip Steps 3 & 4. AS automatically adds the JAR to your build.gradle dependencies. – Wing Poon Mar 11 '17 at 21:22
-
2skip steps 3 and 4, then open File->Project Structure->app->dependencies-> click + -> jar dependencies and choose jar file. its work for me – Jhohannes Purba Mar 31 '17 at 08:07
The GUI based approach would be to add an additional module in your project.
- From the File menu select Project Structure and click on the green plus icon on the top left.
- The new Module dialog pops
- From the phone and tablet application group select the "Import JAR or AAR package" option and click next.
- Follow the steps to create a new module that contains your JAR file.
- Click on the entry that corresponds to your main project and select the dependencies tab.
- Add a dependency to the module that you created in step 4.
One final piece of advice. Make sure that the JAR file you include is build with at most JDK 1.7. Many problems relating to error message "com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)" root straight to this :0.

- 691
- 5
- 11
-
Do you confirm this approach is better than "copy-jar-to-libs" folder approach as other answers says? – Eido95 Jun 13 '17 at 17:14
-
@Eido95 This is how I did it back in 2015. I remember trying to include JSON parsing in an Android application and this is what actually worked. – thanassis Jun 13 '17 at 19:16
-
Which approach do you recommend I should I use in your opinion for simple external JAR addition? – Eido95 Jun 13 '17 at 20:15
A simple way to add Jar file Android Studio Steps:
- Copy and paste your jar file to libs folder of your project.
- Click File from File menu -> Project Structure (CTRL + SHIFT + ALT + S on Windows/Linux, ⌘ + ; on Mac OS X).
- Select Modules at the left panel -> Dependencies tab.
- Add... → Project Library → Attach Jar.

- 5,949
- 5
- 36
- 46
If anyone is looking for another solution without actually copying the jar file(s) into the project directory, e.g. when using a jar in multiple projects:
Open build.gradle and add
def myJarFolder = 'C:/Path/To/My/Jars'
[...]
dependencies {
[...]
compile fileTree(dir: myJarFolder + '/jar/Sub/Folder/1', include: ['*.jar'])
compile fileTree(dir: myJarFolder + '/jar/Sub/Folder/2', include: ['*.jar'])
[...]
}
Note that of course you don't have to use the myJarFolder variable, I find it useful though. The path can also be relative, e.g. ../../Path/To/My/Jars.
Tested with AndroidStudio 3.0
Update: For Gradle Plugin > 3.0 use implementation instead of compile:
dependencies {
[...]
implementation fileTree(dir: myJarFolder + '/jar/Sub/Folder/1', include: ['*.jar'])
implementation fileTree(dir: myJarFolder + '/jar/Sub/Folder/2', include: ['*.jar'])
[...]
}

- 146
- 1
- 6
-
I'm having an issue with this. I am doing it an a library and the app that depends on the library is running into NoClassDefFoundError. I am also getting a lot of errors around not being able to find the class for desugaring – tricknology Nov 01 '18 at 07:43
- Create
libs
folder under app folder and copy jar file into it. - Add following line to dependcies in app
build.gradle
file:
implementation fileTree(include: '*.jar', dir: 'libs')

- 81
- 1
- 2
If you dont see option "Add as Library", make sure you extract (unzip) your file so that you have mail.jar
and not mail.zip
.
Then right click your file, and you can see the option "Add as library".

- 209,280
- 17
- 206
- 263

- 21
- 1
Please provide the jar file location in build.gradle
implementation fileTree(dir: '<DirName>', include: ['*.jar'])
Example:
implementation fileTree(dir: 'C:\Downloads', include: ['*.jar'])
To add single jar file
implementation files('libs/foo.jar')
Note: compile is deprecated in latest gradle, hence use implementation instead.

- 1,599
- 1
- 20
- 24
The "official way" to add a jar into your android project as an external library, is to add the jar in dependencies { } section in build.gradle.
If you've done all of the above, and none of the above works, then there are two other possibilities:
- If Android Studio or some other IDE doesn't give red underlined errors in editor but runs in error in the Java Compiler, CHECK YOUR JAR. Your jar may not have a proper Manifest included therefore the compiler doesn't know what the jar can provide/don't know it's package name
- Maybe it's folder structure is messed up. The folder structure doesn't match with its package name.
package a.b.c;
should be matching to folder a > folder b > folder c. - The package name has some conflict. (Trust me, this happened to me and it took hours to figure it out.)
However, if you are going with cordova, here are some tips of adding external jars.
"build-extras.gradle" is the better way to manage your gradle file.
Here are the steps to manage extra settings in cordova-based android project:
- Adding your jar into build-extras.gradle:
//Other settings go here, e.g.: buildscript { ... } ext.postBuildExtras = { // you may have some other settings, e.g.: android { ... } dependencies { compile files('libs/abc.jar') } }
(More detailed steps here: Extending the cordova gradle file to include google services )
- In terminal, do:
cordova build android

- 1,226
- 13
- 15
Manually:
- Add
libs
folder in your project(Wherebuild.gradle
is located). E.g. app - Move .jar into
libs
- Add
implementation files('libs/<name>.jar')
intobuild.gradle
. It is the same as UIAdd as library
do

- 29,217
- 8
- 193
- 205