Tips

How to adding external library in Android Studio?

Posted on

Android Studio provides a unified environment where you can build apps for Android phones, tablets, Android Wear, Android TV, and Android Auto. Structured code modules allow you to divide your project into units of functionality that you can independently build, test, and debug.

Moreover, adding an external library in Android Studio is a very common thing but still, most beginners or freshers find it difficult to do. So let’s learn how to add any external library to our Android Studio project.

Three ways of adding an external library as follows:

  1. Adding Gradle dependency.
  2. Adding .jar or .aar dependency.
  3. Adding dependency as a module.

1. Adding Gradle Dependency

It is very easy to add Gradle dependency. Most of us are familiar with this method as it is a common way and recommended too.

Suppose you want to add Picasso to your project then you can add Gradle dependency as mentioned below to your project in build.gradle at the app level inside the dependencies block.

2. Adding .jar/.aar Dependency

In some cases, we don’t get the Gradle dependency of the library. Instead, we get only the .jar/.aar file. In such case you can follow the below steps:

  1. Find the .jar/.aar file and download it.
  2. Then copy the file from the downloaded location and go to Android Studio.
  3. Go to the App module and paste the file inside the libs folder. (If you don’t see the libs folder, create a new directory inside the App module.)
  4. After adding the file right-click on it and select Add As Library.
    Then select the module you want to add the library into
  5. By doing that it will be added to your project and you can access the library.

3. Adding dependency as a module

There can be a situation when we need to modify the library code according to our requirement then in that case we can follow this method.

  1. Go to the Github repo link of the library you are looking for.
  2. Click on the green color Code dropdown button
  3. Select Download Zip and save it in your system.
  4. Once downloaded extract the code.
  5. You will find the two main directory name samples and other <library name>.
  6. Go to Android Studio and navigate to File -> New -> Import Module -> Select the library path -> Finish.
  7. Then right-click on the App directory -> Open Module Settings -> Dependencies -> Click on + button inside Declared Dependencies -> Module Dependency -> Select your library -> Ok.

Join Tip3X on Telegram 


Most Popular

Exit mobile version