The Wayback Machine - https://web.archive.org/web/20240930153106/https://www.geeksforgeeks.org/how-to-add-a-library-project-to-android-studio/
Open In App

How to Add a Library Project to Android Studio?

Last Updated : 28 Apr, 2022
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Adding an external library in Android Studio is a very common thing but still, most beginners or freshers find it difficult to do. Some of you must have gone through this. Whenever you want to add some external library and you try to do that with maven(File > Project Structure > Dependencies) and try to add your dependencies there but when you hit Gradle sync, it fails. So now, without fixing this, you want to go for building your app then you will get the error: Error: A problem occurred configuring project ‘:app’. There are many external libraries available that make many specific tasks simple and easy with the APIs and Classes they provide. So including all those libraries in our project is really going to help you a lot. Many developers are often confused about how to add these libraries to their projects. This article is helpful for all such people.

In this article, we will see different ways to add library projects to our project. But before jumping to that let’s have a quick look at this: We can use Gradle, to add library projects with a single line code. Android Studio Project has a modular structure and we have a main module called “app”. There may be multiple modules in a Project. We can connect them together through Gradle, this connection is known as Dependency. Now Let’s get back to our main agenda.

Different Ways To Add Library Project to Android Studio

Method 1

Almost every well-known Android library is available in a Maven repository and its installation takes only one line of code in the app/build.gradle file:

dependencies {

    compile ‘com.jakewharton:butterknife:6.0.0’

}

Let’s add the external library to our project:

Step 1: Create a new project using Android Studio and name it anything you want (GFG in this example) and hit the finish button.

Step 2: The original project structure created by Android Studio looks like this:

Step 3: In the root directory (GFG/), create a new folder: /libs in which we’ll place our external libraries (this step is not required – only for keeping a cleaner project structure).

Step 4: Paste your library in the newly created /libs folder. For this example, we are using the PagerSlidingTabStrip library (you just need to download ZIP from GitHub, rename the library directory to “PagerSlidingTabStrip” and copy it). The new structure of our project should look like this:

Step 5: Edit settings.gradle by adding your library to include. If you use a custom path like I did, you have also to define the project directory for our library. A whole settings.gradle should look like below:

include ‘:app’, ‘:PagerSlidingTabStrip’

project(‘:PagerSlidingTabStrip’).projectDir = new File(‘libs/PagerSlidingTabStrip’)

Step 5.1: If you face “Default Configuration” error, then try this instead of step 5,

   include ‘:app’

   include ‘:libs:PagerSlidingTabStrip’

Step 6: In app/build.gradle add our library project as a dependency:

dependencies {

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

   compile ‘com.android.support:appcompat-v7:21.0.3’

   compile project(“:PagerSlidingTabStrip”)

}

Step 6.1: If you followed step 5.1, then follow this instead of 6,

      dependencies {

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

       compile ‘com.android.support:appcompat-v7:21.0.3’

       compile project(“:libs:PagerSlidingTabStrip”)

   }

Step 7: If your library project doesn’t have build.gradle file you have to create manually. 

Step 8: That’s all. Just click‚ sync the project with Gradle. Your library should be available for your project.

Method 2

Step 1: Follow to File > New Module

Click on “Import Existing Project“.

Step 2: Select the desired library and the desired module. Then click finish. Android Studio will import the library into your project and will sync Gradle files.

Step 3: In the next step you need to add the imported module to your project’s dependencies. Right-click on the app folder > Open Module settings 

Step 4: Navigate to the dependencies tab > Click on the ‘+’ button -> click on Module Dependency. The library module will be then added to the project’s dependencies.

Method 3

Step 1: Navigate to  File > Project Structure 

Step 2: Then click on Modules.

To import the library using Gradle, you can have to add it to the dependencies section of your build.gradle (the module’s one).

Method 4

Just go to Project Structure > under Modules (see below images) just click the plus button and select Import Existing Project and import. Then sync your Gradle files. There are chances to face the error

Error: The SDK Build Tools revision (xx.x.x) is too low. Minimum required is yy.y.y

Then just open the build.gradle file in your library project directory and update the buildToolsVersion to the suggested one.

android {

 compileSdkVersion 19

 buildToolsVersion ‘yy.y.y’ 

}

then try importing the module by clicking on File > Project Structure

Module > Import Module

After importing the library module, select your project module and add the dependency and then select the imported module.



Similar Reads

How to Add Support Library to Android Studio Project?
An android support library is part of Android SDK tools. You can use the Android Support Library for backward-compatible versions of new Android features and additional UI elements and features not included in the standard Android framework. Each package in the support library has a version number in three parts (X.Y.Z) that correspond to an Androi
3 min read
How to Add OpenCV library into Android Application using Android Studio?
OpenCV is the huge open-source library for computer vision, machine learning, and image processing and now it plays a major role in real-time operation which is very important in today’s systems. By using it, one can process images and videos to identify objects, faces, or even the handwriting of a human. When it integrated with various libraries,
3 min read
Fix "Error running android: Gradle project sync failed. Please fix your project and try again" in Android Studio
In this article, we will see how to fix the error: "Gradle project sync failed. Please fix your project and try again" in Android Studio". Before getting into the solution part, let's discuss Gradle. What is Gradle? Gradle is an open-source build automation tool that automates the creation of applications. The various steps involved in creating an
5 min read
How to Add Resource File in Existing Android Project in Android Studio?
Android resource file is a file that stores resources needed for the UI part of an android application. Like: Layout files, drawable files, etc. In the android application, it is very often that we need another resource file for another purpose in the existing application. There are many types of resource files Layout files, Drawables, Menus are so
1 min read
How to fix "Android Studio doesn't see device" in Android Studio?
In Android Studio, sometimes the list of devices and emulators doesn't list your physical device when you try to plug it in. Or you may have faced a situation when you plugged the phone in for the first time, no dialog appeared asking if you trust the computer. But the laptop is already allowed to connect to the mobile device. However, the button R
4 min read
How to Fix "Android studio logcat nothing to show" in Android Studio?
Logcat Window is the place where various messages can be printed when an application runs. Suppose, you are running your application and the program crashes, unfortunately. Then, Logcat Window is going to help you to debug the output by collecting and viewing all the messages that your emulator throws. So, this is a very useful component for the ap
2 min read
How to Add External Library in Android Studio?
Android Studio is the official IDE (Integrated Development Environment) for Android app development and it is based on JetBrains’ IntelliJ IDEA software. Android Studio provides many excellent features that enhance productivity when building Android apps. In this article, we will learn how to add external libraries to our android project. Method 1:
2 min read
Android Studio Project Structure VS Eclipse Project Structure
Eclipse is a standard package that is ideal for java and plug-in development, as well as introducing new plugins. Eclipse is mostly used for Java because it is basically developed in Java. One of the reasons Eclipse is well-known for its Java IDE is because of this. To personalize the environment, Eclipse includes its own workspace and a flexible p
4 min read
Different Ways to Add Stacktrace or debug Option when Building Android Studio Project
While developing your favorite app, you might at some point of time arrived upon this strange error, :GfGapp:processDebugResources FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:processDebugResources'. * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to
2 min read
How to Clone Android Project from GitHub in Android Studio?
Android Studio provides a platform where one can build apps for Android phones, tablets, Android Wear, Android TV, and Android Auto. Android Studio is the official IDE for Android application development, based on IntelliJ IDEA. One can develop Android Applications using Kotlin or Java as the Backend Language, and it provides XML for developing Fro
3 min read
Different Ways to fix "Error running android: Gradle project sync failed" in Android Studio
Gradle is one of the most important components of Android apps. It handles all the backend tasks and manages all the external dependencies which we will be going to use in building our Android Application. Sometimes due to any issue or after formatting of your pc. Some of the Gradle files may get deleted unexpectedly. So when you will start buildin
3 min read
How to Add Audio Files to Android App in Android Studio?
The audio file format is a file format for saving digital audio data on a computer system and all are aware of audio files. So in this article, we are going to discuss how can we add audio files to the android app. There are three major groups of audio file formats: Format Name Description Examples Uncompressed audio formatsUncompressed audio forma
3 min read
How to Add Firebase Analytics to Android App in Android Studio?
Analytics is one of the important tools that developers should definitely used while building their applications. It is very helpful to target your apps for various audience ranges and to track on which screen the users are spending a long time. So it is one of the important features which one should not miss adding while building any Android Appli
4 min read
Neumorphism Library in Android Studio
Neumorphism is a design concept used to make soft widgets based on object shadows. It uses highlights and shadows to create elements that appear to be floating above the surface. In other words, the object seems to extrude from the background. It is a beautiful theme in which we can add a little elevation to the views of our layout components to ma
3 min read
How to Include *.so Library in Android Studio?
The SO file stands for Shared Library. You compile all C++ code into the.SO file when you write it in C or C++. The SO file is a shared object library that may be dynamically loaded during Android runtime. Library files are larger, often ranging from 2MB to 10MB in size. As a result, the app becomes bloated. Another thing to keep in mind is that se
3 min read
Different Ways to Search All the Occurrences of a String in the Entire Project in Android Studio
When we are building a complex application in Android Studio, then it is always preferable to have a basic idea about the different shortcut keys which are used in Android studio to make your tasks easier. So in this article, we will take a look at some shortcut keys which we can use to find usages of any string variable in your entire Android Proj
3 min read
Different Ways to Change the Project Name in Android Studio
When you have worked a lot on an Android project and then if you need to rename the project there are lots of configuration files, .xml files, and gradle files in Android Studio that you’re afraid to break things up. Sometimes we end up creating a new Android Studio project, with the correct name and then pass the source files from the old project
2 min read
Different Ways to Set Gradle Home While Importing Existing Project in Android Studio
Gradle has its own Groovy library, thus it is not necessary to install Groovy. Gradle ignores any current Groovy installation. Gradle will utilize the first JDK it finds in your path. Alternatively, you may change the JAVA HOME environment variable to refer to the appropriate JDK's installation location. But sometimes, as software is unpredictable,
2 min read
How to Create Admin & Client App in One Project Using Android Studio?
You all must know about projects in which two applications are required one for the client and the other for the admin. Here we will see how we can implement both the applications under a single project in android studio. Let us see the step-by-step implementation of this procedure. Step by Step Implementation Step 1. Create a new project Open a ne
2 min read
Flutter - Android Studio Not Showing Project Files
There are a couple of errors that come up while making an Android app. Making the project requires less time rather than debugging the same project with errors. One such error is that when we develop a project and when we open it after a few days it does not show us the files present in the folder, assets folder, pubspec.yaml, and various other fil
3 min read
How to Create/Start a New Project in Android Studio?
After successfully installing the Android Studio and opening it for the first time. We need to start with some new projects to start our journey in Android. In this article, we will learn about How to Create a New Project in Android Studio. Steps to Create/Start a New Android Project in Android Studio Below are the steps to start and set up a new A
2 min read
How to Upload Project on GitHub from Android Studio?
Uploading your project to GitHub directly from Android Studio simplifies your development workflow and helps you share your code with others easily. Here’s a step-by-step guide on how to upload your project on GitHub from Android Studio. Steps to Upload Project on GitHub from Android StudioStep 1: Go to VCS panel which is present at the top of Andr
2 min read
How to Create a New Project in Android Studio Canary Version with Jetpack Compose?
Jetpack Compose is a new toolkit provided by Google. This is useful for designing beautiful UI designs. After the successful installation of the Android Studio Canary version, we are moving towards the creation of a new Project. In this article, we will take a look at How to create a new project in the Android Studio Canary Version using Jetpack Co
2 min read
How to Add Local HTML File in Android Studio?
HTML stands for HyperText Markup Language. It is used to design web pages using a markup language. HTML is the combination of Hypertext and Markup language. Hypertext defines the link between the web pages. A markup language is used to define the text document within the tag which defines the structure of web pages. HTML is a markup language that i
3 min read
How to Add Different Resolution Images in Android Studio?
Android supports a broad range of devices and if one wants to create an application in android then the application must be compatible with the different mobile devices. For supporting the different screen sizes one must have different size images that will save in multiple folders. Normally Android has four folders that cover almost every device:
2 min read
How to Add Image to Drawable Folder in Android Studio?
The resource folder is the most important folder because it contains all the non-code sources like images, XML layouts, UI strings for the android application. In Android Studio inside the res folder, one can find the drawable folder, layout folder, mipmap folder, values folder, etc. Among them, the drawable folder contains the different types of i
3 min read
Different Ways to Change or Add Themes to Android Studio
When we are working on any editor or IDE we get used to it and its environment like if we are using Sublime then we like its dark background environment. We have now moved to Android studio but we are not comfortable with the default background and theme. Now the point that comes here is how we can Change or Add Themes to Android Studio. So in this
3 min read
How to Add Vector Assets in Android Studio?
Vector Assets in Android Studio helps to add material icons and import Scalable Vector Graphics and Adobe Photoshop Document files into your project as vector drawable resources. How Vector Asset is different from Image Asset? Image Asset Studio helps us create different types of icons with different densities and shows us exactly where they'll be
3 min read
How to Install Genymotion Emulator and Add it’s Plugin to Android Studio?
If you're an Android developer looking for a powerful and efficient emulator, installing the Genymotion emulator might be the perfect solution for you. Known for its speed and reliability, the Genymotion emulator for Android development offers a seamless experience. In this guide, we'll walk you through the steps to install the Genymotion emulator
5 min read
Different Ways to Change Android SDK Path in Android Studio
Android SDK is one of the most useful components which is required to develop Android Applications. Android SDK is also referred to as the Android Software Development Kit which provides so many features which are required in Android which are given below: A sample source code.An Emulator.Debugger.Required set of libraries.Required APIs for Android
5 min read
Article Tags :