How do I add a library project to Android Studio?

Alexander Kulyakhtin 08/22/2017. 29 answers, 544.786 views
android android actionbarsherlock android-library android-studio android-studio

How do I add a library project (such as Sherlock ABS) to Android Studio?

(Not to the old ADT Eclipse-based bundle, but to the new Android Studio.)

25 Daniel Smith 05/21/2013
yeah figuring this out was way more confusing than it should have been... not like it was any better in eclipse.
3 user1785900 01/19/2014
The YouTube video How to Add Libraries to Android Studio explains the process.
1 craned 10/16/2014
If you're using Gradle, see this StackOverflow answer.
1 Simon 12/20/2014
Here is a video which I found to be really useful:

29 Answers

froger_mcs 05/23/2017.

Update for Android Studio 1.0

Since Android Studio 1.0 was released (and a lot of versions between v1.0 and one of the firsts from the time of my previous answer) some things has changed.

My description is focused on adding external library project by hand via Gradle files (for better understanding the process). If you want to add a library via Android Studio creator just check the answer below with visual guide (there are some differences between Android Studio 1.0 and those from screenshots, but the process is very similar).

Before you start adding a library to your project by hand, consider adding the external dependency. It won’t mess in your project structure. 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'

Adding the library

Here is the full process of adding external Android library to our project:

  1. Create a new project via Android Studio creator. I named it HelloWorld.
  2. Here is the original project structure created by Android Studio:
           - build.gradle  // local Gradle configuration (for app only)
      - build.gradle // Global Gradle configuration (for whole project)
      - settings.gradle
  1. In the root directory (HelloWorld/), create new folder: /libs in which we’ll place our external libraries (this step is not required - only for keeping a cleaner project structure).
  2. Paste your library in the newly created /libs folder. In this example I used PagerSlidingTabStrip library (just download ZIP from GitHub, rename library directory to „PagerSlidingTabStrip" and copy it). Here is the new structure of our project:
           - build.gradle  // Local Gradle configuration (for app only)
                - build.gradle // Local Gradle configuration (for library only)
      - build.gradle // Global Gradle configuration (for whole project)
      - settings.gradle
  1. 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')

5.1 If you face "Default Configuration" error, then try this instead of step 5,

    include ':app'
    include ':libs:PagerSlidingTabStrip'
  1. In app/build.gradle add our library project as an dependency:

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile ''
        compile project(":PagerSlidingTabStrip")

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

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

        compile project(":libs:PagerSlidingTabStrip")
  1. If your library project doesn’t have build.gradle file you have to create it manually. Here is example of that file:

        apply plugin: ''
        dependencies {
            compile ''
        android {
            compileSdkVersion 21
            buildToolsVersion "21.1.2"
            defaultConfig {
                minSdkVersion 14
                targetSdkVersion 21
            sourceSets {
                main {
                    manifest.srcFile 'AndroidManifest.xml'
                    java.srcDirs = ['src']
                    res.srcDirs = ['res']
  2. Additionally you can create a global configuration for your project which will contain SDK versions and build tools version for every module to keep consistency. Just edit file and add lines:


    Now you can use it in your build.gradle files (in app and libraries modules) like below:

    android {
        compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
        buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
        defaultConfig {
            minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)
            targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
  3. That’s all. Just click‚ synchronise the project with the Gradle’ icon synchronise with Gradle. Your library should be available in your project.

Google I/O 2013 - The New Android SDK Build System is a great presentation about building Android apps with Gradle Build System: As Xavier Ducrohet said:

Android Studio is all about editing, and debugging and profiling. It's not about building any more.

At the beginning it may be little bit confusing (especially for those, who works with Eclipse and have never seen the ant - like me ;) ), but at the end Gradle gives us some great opportunities and it worth to learn this build system.

6 victor n. 05/24/2013
hey there, you perfectly explained the real issue. voting up your answer so other people can see it. one minor thing that didn't work on my side is referencing the support library in the dependency's build.gradle. as it turns out ':Project/libs...' did not work for some reason. i had to do away with the project identification. so 'libs/...'. and it compiled fine. one note is that these two ways of referencing paths or projects is confusing. i hope a simple and unified scheme comes up in the future. there is no reason why the original solution wouldn't work.
9 Akbar ibrahim 05/24/2013
+1. Was struggling with this for a long time. As victor n said, referencing the main project's support jar from actionbarsherlock module doesn't work. I had to do the following to get it working... (1) Remove compile files('libs/android-support-v4.jar') from the project's build.gradle. The main module should only have compile project(":libraries:actionbarsherlock"). (2) Add compile files('libs/android-support-v4.jar') instead of compile files(':HelloWorld/libs/android-support-v4.jar') in actionbarsherlock's build.gradle.
8 alicanbatur 11/07/2013
Why dont i have "Import Module" section, at the option where you direct us ? I'm using Android Studio 0.3.1
5 amalBit 02/08/2014
Import Module option is missing!!
147 Kyle Gobel 10/19/2014
Why is this so god damn confusing?!

Sam Rad 07/01/2016.

Here is the visual guide:

Update for Android Studio 0.8.2:

In Android Studio 0.8.2, go to Project Structure -> under Modules just hit the plus button and select Import Existing Project and import actionbarsherlock. Then synchronise your Gradle files.

If you face the error

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

just open the build.gradle file in actionbarsherlock directory and update the buildToolsVersion to the suggested one.

android {
  compileSdkVersion 19
  buildToolsVersion 'yy.y.y'

Android Studio 0.8.2

Menu 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:


29 amalBit 02/08/2014
Import module option not available in Android Studio4.3
3 toobsco42 08/25/2014
The key for me to make this work and resolve the package not found errors was the step Select your project module and add dependency dependencies { // ... compile project(':library') }
6 Rémy DAVID 10/06/2014
This will copy the library module in your project, which is not what you want if you want a common code base shared between several projects
CCJ 11/13/2015
@amalBit are... are you from the future? But seriously, they need to make this simple like it was in Eclipse ADT; who wants to hit a third-party repo and compile (potentially) arbitrary code into each build? That seriously undermines QA and code-freeze protocols
amalBit 11/17/2015
It was way back during beta days of Android studio 0.4.3. As for accession 3rd party repo, id say, avoid using +. Just specify the version u want. If u still cant trust it enough, u can create a jar(or clone) of any repo and use it.

Blackbelt 07/01/2016.

Use menu File -> Project Structure -> Modules.

I started using it today. It is a bit different.

For Sherlock, maybe you want to delete their test directory, or add the junit.jar file to the classpath.

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


dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile ''
    compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'

Android Studio is changing.

There exist a section named "Open module settings" if you right-click on a module folder in the project section of Android Studio (I'm using the version 0.2.10).

1 Alexander Kulyakhtin 05/16/2013
Hmm it still says android-apt-compiler: styles.xml:5: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.Sherlock.Light.DarkActionBar'.
Blackbelt 05/16/2013
Under the Sherlock Module -> Dependecies I have android 4.2.2 and the support Library v4
Blackbelt 05/16/2013
@ρяσѕρєяK next to the run button, there is a label with Android. If you ckick there you will find Edit Configuration. Push and under Target Device click on "Show Chooser Dialg"
7 fish 05/16/2013
Hi, I've the same problem like Alex ("Gradle: Error retrieving parent for item: No resource found that matches the given name 'Theme.Sherlock.Light'.") - the Java dependency seems to be solved correctly, cause the IDE doesn't blame my SherlockActivity, but for some reason Gradle doesn't seem to look into the ressources of ABS. Any ideas?
4 Konrad Morawski 09/15/2013
On Android Studio 0.2.8 there is no Modules section in the Project Structure window.

Jonathan Lin 10/14/2013.

I would consider Dependencies, Android Libraries and Multi-project setup necessary reading. Please take a few minutes to do so.

Particularly, in the case of a non-jar library project, read the following snippet from above source:

Gradle projects can also depend on other gradle projects by using a multi-project setup. A multi-project setup usually works by having all the projects as sub folders of a given root project.

For instance, given to following structure:

 + app/
 + libraries/
    + lib1/
    + lib2/

We can identify 3 projects. Gradle will reference them with the following name:


Each projects will have its own build.gradle declaring how it gets built. Additionally, there will be a file called settings.gradle at the root declaring the projects. This gives the following structure:

 | settings.gradle
 + app/
    | build.gradle
 + libraries/
    + lib1/
       | build.gradle
    + lib2/
       | build.gradle

The content of settings.gradle is very simple:

include ':app', ':libraries:lib1', ':libraries:lib2'

This defines which folder is actually a Gradle project.

The :app project is likely to depend on the libraries, and this is done by declaring the following dependencies:

dependencies {
    compile project(':libraries:lib1')

Kindly note that there was little or no use of Android Studio GUI to make this happen.

I am currently using git submodules to link the nested library to the actual library git repo to avoid a dependency mess.

Jonathan Lin 10/14/2013
Kindly upvote if you found this helpful, so that others can avoid the pain and move along faster.
RichieHH 03/24/2014
Very helpful and, more importantly, not play to the gui whims of the day.
1 dcunited001 04/20/2014
thank you so much for including the only answer that makes sense. every other answer is outdated and just doesn't work. i didn't even try in CS at Virginia Tech because the whole first two years was learning to fckn click around in eclipse. it didn't make any fckn sense, but seeing the gradle result of random clicks in an IDE does.
velis 06/01/2015
Thanks for the git submodules tip. I was using junction before, but have now switched to SVN externals. Works like a charm.

René Michel 07/01/2016.

I have just found an easier way (rather than writing directly into the .gradle files).

This is for Android Studio 1.1.0.

  1. Menu File -> New Module...:

    Import Existing Project

    Click on "Import Existing Project".

  2. Select the desired library and the desired module.

  3. Click finish. Android Studio will import the library into your project. It will sync gradle files.

  4. Add the imported module to your project's dependencies.

    Right click on the app folder -> Open Module settings -> go to the dependencies tab -> Click on the '+' button -> click on Module Dependency.

    The library module will be then added to the project's dependencies.

    Add library module

  5. ???

  6. Profit

Vilen 07/01/2016.

The easiest way I found to include external library project is (for example to include a Facebook library which is stored one directory up in the dependencies folder):

  1. In settings.gradle add

    include ':facebook'
    project(':facebook').projectDir = new File(settingsDir, '../dependencies/FacebookSDK')
  2. In build.gradle dependencies section, add

    compile project ('facebook')

All left to do is synchronise the project with gradle files.

Rajnish Mishra 03/23/2015
Hi Vilen what is settingsDir here
Vilen 04/02/2015
Hi Rajnish. From documentation: settingsDir Returns the settings directory of the build. The settings directory is the directory containing the settings file. Returns: The settings directory. Never returns null.
Rajnish Mishra 04/03/2015
The two dots before /dependencies are more important to be cared Your answer helper me a lot.. Thanks
Solata 11/18/2015
NOTE: for string evaluation in gradle you must use double quote ("). This "save the day" for me. Linked to this

Eugene Bosikov 07/01/2016.

A simple way to add a JAR file as a library to your Android Studio project:

a) Copy your *.jar files

b) Paste into the libs directory under your projects:

Enter image description here

c) Add to build.gradle:

dependencies {
    compile files('libs/ScanAPIAndroid.jar', 'libs/ScanAPIFactoryAndroid.jar', .., ..)

b) If your project from example com.example.MYProject and libraries com.example.ScanAPI has the same namespace com.example, Android Studio will check your build and create all necessary changes in your project. After that you can review these settings in menu File -> Project Structure.

c) If your project and libraries have a different namespace you have to right click on the library and select option "Add as Library" and select the type what you need.

Remember the "Project structure" option is not doing any auto changes in "build.gradle" in the current version of Android Studio (0.2.3). Maybe this feature will be available in the next versions.

pathe.kiran 06/27/2016.

Option 1: Drop Files Into Project's libs/directory

The relevant build.gradle file will then update automatically.

Option 2: Modify build.gradle File Manually

Open your build.gradle file and add a new build rule to the dependencies closure. For example, if you wanted to add Google Play Services, your project's dependencies section would look something like this:

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

Option 3: Use Android Studio's User Interface

In the Project panel, Control + click the module you want to add the dependency to and select Open Module Settings.

Enter image description here

Select the Dependencies tab, followed by the + button in the bottom-left corner. You can choose from the following list of options:

  • Library Dependency
  • File Dependency
  • Module Dependency

You can then enter more information about the dependency you want to add to your project. For example, if you choose Library Dependency, Android Studio displays a list of libraries for you to choose from.

Once you've added your dependency, check your module-level build.gradle file. It should have automatically updated to include the new dependency.


drewan50 07/01/2016.

If you need access to the resources of a library project (as you do with ABS) ensure that you add the library project/module as a "Module Dependency" instead of a "Library".

1 cosimo 04/01/2014
Yes! You sir win the Internet! Thanks! I have just wasted a couple of hours of my life because I didn't know that.

pandabear 07/01/2016.

This is how it works for me in Android Studio 1.5

In the project where you want to add external library project, go to menu File -> New -> *Import new Module**, navigate to the library project which you want to add to your project, select to add 'library' module in your project. You will get settings.gradle in your projects, beside app, included library, something like this:

include ':app', ':library'

Add in build.gradle(Module :app) in the dependencies section:

Compile project(':library')

Rebuild the project, and that's it.

*You can add as many libraries (modules) as you want. In that case in settings.gradle you will have:

 include ':app', ':lib1', ':lib2', ...

And in build.gradle, you'll need to have:

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

    // Some other dependencies...

    compile project(':lib1')
    compile project(':lib2')

Adiii 07/01/2016.

You can do this easily. Go to menu File -> New -> Import Module...:

Enter image description here

Browse for the directory which contains the module. Click Finish:

Enter image description here

Go to Project Structure and add Module Dependency:

Enter image description here

Note: If you receive an SDK error, update that one.

Dalmas 06/27/2016.

To add to the answer: If the IDE doesn't show any error, but when you try to compile, you get something like:

No resource found that matches the given name 'Theme.Sherlock.Light'

Your library project is probably compiled as an application project. To change this, go to:

Menu File -> Project structure -> Facets -> [Library name] -> Check "Library module".

crossle 07/01/2016.
  1. Press F4 to show Project Structure, click libraries or Global libraries, and click + to add the JAR file.
  2. Click Modules what you want add jar, select the Dependencies tab, click +, and add Library.

Shakti Malik 07/01/2016.

Editing library dependencies through the GUI is not advisable as that doesn't write those changes to your build.gradle file. So your project will not build from the command-line. We should edit the build.gradle file directly as follows.

For instance, given to following structure:


  • app/
  • libraries/
    • lib1/
    • lib2/

We can identify three projects. Gradle will reference them with the following names:

  1. :app
  2. :libraries:lib1
  3. :libraries:lib2

The :app project is likely to depend on the libraries, and this is done by declaring the following dependencies:

dependencies {
    compile project(':libraries:lib1')
Alexander Kulyakhtin 05/23/2013
Really? Strange, they have the whole GUI and yet it's not advisable. How so?
Shakti Malik 05/23/2013
As editing through GUI doesn't writes those changes to your build.gradle file. GUI editing only saves changes in IntelliJ's own project data. This is a bug at the moment which will be fixed in future releases. You can refer to this answer from Google Android-Studio Team Lead…

Erwan 05/17/2013.

After importing the ABS Module (from File > Project Structure) and making sure it has Android 2.2 and Support Library v4 as dependencies, I was still getting the following error as you @Alex

Error retrieving parent for item: No resource found that matches the given name 'Theme.Sherlock.Light.DarkActionBar'

I added the newly imported module as a dependency to my main app module and that fixed the problem.

christiaanderidder 05/19/2013
I tried all steps inclusing adding the module as a dependency but I still have Gradle: Error retrieving parent for item: No resource found that matches the given name 'Theme.Sherlock.Light'.. It seems like my main project does not see the resources of the library project (ABS). The IDE however does recognize the references to classes and resources. Screenshot
Calvin Chan 06/04/2013
Same here. Who can solved this?
Dmitriy Tarasov 06/06/2013
I'm migrate to IDEA 13 from 12 and have this error too. Only re-import for all my dependencies will help. Manually remove all modules, remove related *.iml files and re-import your libs

azh 02/09/2014.

To resolve this problem, you just need to add the abs resource path to your project build file, just like below:

sourceSets {
    main {
        res.srcDirs = ['src/main/res','../../ActionBarSherlock/actionbarsherlock/res']

So, I again compile without any errors.

Hemant 07/01/2016.

First Way This is working for MacBook.

First select your builder.gradle file as given screen:

Enter image description here

Add dependencies like as on the selected screen:

Enter image description here

Select sync project.

If you are getting an error like "Project with path':signature-pad' could not be found in project ':app'", then please use the second way:

Select menu File -> New -> Import Module...:

Enter image description here

After clicking on Import Module,

Enter image description here

give the path of library like as my MacBook path:

Enter image description here

Click on Finish. Now your library are added.

Braunster 02/09/2014.

If you have Android Studio .0.4.0, you can create a new folder in your build path, YourApp/libraries. Copy the JAR file. There in, right click on it and "Add As Library". Now you have a popup. Just select your directory and press OK, and that's it.

ankitbumblebee 07/01/2016. is the Dropbox link of how to add a JAR file and library project in the latest version of Android Studio 1.0.1.

Please see the documentation with screenshots. It's very easy for a new user.

passsy 05/23/2017.

I found the solution. It's so simple. Follow froger_mcs instructions.

Make sure that you make the src folder a Source folder in Project Structure -> Modules (Sources).

Enter image description here

voghDev 05/23/2017.

An example of succesfully adding another library (PullToRefresh). Also works for ABS libproject.

This SO Question

This post

Mohammad 05/23/2017.

Basically, you can include your JAR files in three different ways. The last one is remote library that is using jcenter online repository. But, if you do it in one of the two other ways, the JAR file will be included physically in your project. Please read this link for more information. In this post I explained how to import your JAR file in Android studio and I explained all possible ways.

In summary, if it is like this (local address), they are downloaded and these JAR files are physically in the project:

enter image description here

But, if it is an internet address like this, they are remote libraries ( jcenter part) and they will be used remotely:

enter image description here

I hope it helps.

Jinu 06/27/2016.

Open the build gradle module app file and add your dependency. If you download the library, just import and build as gradle.

Otherwise add repositories in side gradle module app:

repositories {
        maven { url '' }

The first repositories will download the library for you.

And compile the downloaded library:

 compile ('com.fortysevendeg.swipelistview:swipelistview:1.0-SNAPSHOT@aar') {
        transitive = true

If you are creating a library, you just need to import the project as import new module.

Dharmendra Pratap 06/27/2016.

In Android Studio, go to inside app folder, and open build.gradle file. Here you will see dependencies{}. Inside it you can add the library project and synchronise. Now after synchronising the library it will be added to your project, and you can use its functions and classes in your project.

MAMASSI 07/01/2016.

For Android Studio:

Enter image description here

Click on Build.gradle (module: app).

And add for

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile files('libs/commons-io-2.4.jar')

and in your directory "app", create a directory, "libs". Add the file yourfile.jar:

Enter image description here

Finally, compile the Gradle Files:

Enter image description here

Badre 03/23/2016
dude respect :D

Pankaj kumar 07/01/2016.

Simply import the Android library project as a module and in Build.gradle.

Apply plugin: ''

After that, follow these steps:

  1. Right click on Module & select open Module settings
  2. Select dependencies, click on +, select library dependencies, and add the previously imported module.

jobbert 07/01/2016.

I had a different cause of the problem so for people:

repositories {

change mavenCentral() to jcenter() and add

allprojects {
    repositories {

I also encountered the same problem then I did following things.

  1. I import the library project into my AndroidStudio IDE as a module using menu File -> Import module menus

  2. Then I went to my main module in which I want the library project as a dependent project

  3. Right click on the main module (in my case its name is app) -> open module setting -> go into dependencies tab -> click on + button (you will get it on right side of window) -> click on module dependency -> select your library project from list

Apply the changes and click the OK button.

It worked for me. I hope it will help others too.

monn3t 07/01/2016.

Indeed as versions are changing, so is changing the user interface and options available on the menu. After reading most of the answers to these questions I had to guess what would work for Android Studio 1.1.0.

  1. With your mouse, select the project at the main level (this is where it shows the name of your app).

  2. Right click, and select the menu options New, Folder, Assets Folder.

  3. After creating the assets folder, paste or copy in it, whatever JAR file you need for your library.

  4. From Android Studio's main menu (top of the screen) select File -> Project Structure.

  5. Then select your project name and go to the Dependencies tab.

  6. Click on the plus sign (+) on the lower left of the dialog box and select file dependency.

  7. Finally open the recently created assets folder, select the JAR files that you copied, and then click apply and OK.

Clean and rebuild your project.

1 Rajnish Mishra 03/23/2015
making copies of jars in assets is not a good idea it will unnecessarily increase apk size
monn3t 04/12/2015
Thanks for the advise @RajnishMishra. I suspected that, but what do you propose instead?

Related questions

Hot questions


Popular Tags