Android Studio – Add .Jar File as Android Library

Android Studio – Add .Jar File as Android Library

In this android code snippet tutorial, we will learn how we can easily add a .jar file as android library in Android Studio. If you are using Eclipse IDE for android, you can also read how you can add a .jar file in Eclipse.

In your android development career or hobby, you will get to a point where you will need to use third party libraries for your application. Using third party libraries can be beneficial in many ways and it will reduce the development time and save cost.

The version of Android studio I am using in this tutorial is version 1.1.0. This might vary from older versions.

We are going to highlight two ways we can achieve this. You are free to use the one you like the best.

Before we start, the first thing I will do is to list the environment and tools I used in this android tutorial but feel free to use whatever environment or tools you are familiar with.

Windows 7

Android Studio

Samsung Galaxy Fame Lite

Min SDK 14

Target SDK 19

To create a new android application project, following the steps as stipulated below.

Go to File menu

Click on New menu

Click on Android Application

Enter Project name: AndroidAddJarFile

Package: com.inducesmile.androidaddjarfile

Keep other default selections.

Continue to click on next button until Finish button is active, then click on Finish Button

Once you are done with creating your project, make sure you change the package name if you did not use the same package.

First Method

In the first method, we are going to follow the steps stipulated below.

1. Copy the .jar file and add it to the libs folder in your android project. If your project does not contain any libs directory, you can create the directory in the same level to the project src folder.

2. Then right click on the .jar file and click add as a library then choose a module then ok.

jarfile1

You can see the .jar file in build.gradle file within dependencies block.

jarfile2

That is all you need and it is very simple.

Second Method

1. Copy the .jar file and add it to the libs folder in your android project. If your project does not contain any libs directory, you can create the directory in the same level to the project src folder.

2. Click on file menu and on the pop up menu click on the project structure

jarfile3

3. On the new window, select you app and click on dependency tab to select it.

jarfile4

4. Click on the + sign icon on the top right, choose file dependency and select the dependency file.

Then click apply and OK to finish.

You will see that the .jar file has been added to your build.gradle file

jarfile2

There are many other ways to achieve adding a .jar file in your android studio project. I will like to hear how you use .jar file in your android studio in the comment section.

Add a Comment