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.)
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.)
Basically, you can include your JAR files in three different ways. The last one is remote library that is using https://bintray.com/ 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 https://stackoverflow.com/a/35369267/5475941 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:
But, if it is an internet address like this, they are remote libraries (bintray.com jcenter part) and they will be used remotely:
I hope it helps.
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:Adding the library
Here is the full process of adding external Android library to our project:
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)./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: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:5.1 If you face "Default Configuration" error, then try this instead of step 5,
In
app/build.gradle
add our library project as an dependency:6.1. If you followed step 5.1, then follow this instead of 6,
If your library project doesn’t have
build.gradle
file you have to create it manually. Here is example of that file: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
gradle.properties
file and add lines:Now you can use it in your
build.gradle
files (in app and libraries modules) like below:That’s all. Just click‚ synchronise the project with the Gradle’ icon . 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:
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.
Android Studio 3.0
Just add the library name to the dependencies block of your app's build.gradle file.
Note that you should use
implementation
rather thancompile
now. This is new with Android Studio 3.0. See this Q&A for an explanation of the difference.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.
With your mouse, select the project at the main level (this is where it shows the name of your app).
Right click, and select the menu options New, Folder, Assets Folder.
After creating the assets folder, paste or copy in it, whatever JAR file you need for your library.
From Android Studio's main menu (top of the screen) select File -> Project Structure.
Then select your project name and go to the Dependencies tab.
Click on the plus sign (+) on the lower left of the dialog box and select file dependency.
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.
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
I added the newly imported module as a dependency to my main app module and that fixed the problem.
An example of succesfully adding another library (PullToRefresh). Also works for ABS libproject.
This SO Question
This post