How do I add a library project (such as Sherlock ABS) to the 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 the Android Studio? (Not to the old ADT Eclipse-based bundle, but to the new Android Studio.) |
||||
|
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 library via Android Studio creator just check the answer below with visual guide (there are some differents between Android Studio 1.0 and those from screenshots, but the process is very similar). Before you start adding library to your project by hand consider adding external dependency. It won’t mess in your project structure. Almost every well known Android library is available in maven repository and its installation takes only one line of code in
Adding the library Here is the full process of adding external Android library to our project:
... (Removed outdated description here) ... Here you have great presentation about building Android apps with Gradle Build System - http://www.youtube.com/watch?v=LCJAgPkpmR0. 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. |
|||||||||||||||||||||
|
|
Here is the visual guide for lazy guys like me: 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 If you face the following error:
Just open the
After importing the library module, select your project module and add dependency:
And then select the imported module:
|
|||||||||||||||||||||
|
I started using it today. It is a bit different. For Sherlock, maybe you want to delete their test directory, or add the Edit: AndroidStudio is changing.
thanks |
|||||||||||||||||||||
|
|
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:
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. |
|||||||||||||
|
|
For anyone who may just be finding this. 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". |
|||||
|
|
Simple way to add JAR file as library to your Android Studio project: a) Copy your *.jar files b) Paste into libs directory under your projects
c) Add to build.gradle
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 than you can review these settings in File->Project Structure c) IF Your project and libraries has different namespace you have to RigthClick on library and select OPTION "Add as Library" and select type what you need. Remember "Project structure" option is not doing any auto changes in "build.gradle" in current version Android studio (0.2.3) maybe this feature will be available in next versions. |
|||||
|
|
To add to the answer : If the IDE doesn't show any error but when you try to compile, you get something like :
Your library project is probably compiled as an application project. To change this, go to : File > Project structure > Facets > [Library name] > Check "Library module". |
||||
|
|
|
|||
|
|
|
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. |
|||||||||||||||||
|
|
Editing library dependencies through GUI is not advisable as that doesn't writes those changes to your build.gradle file. So your project will not build from command-line. We should edit build.gradle file directly as follows. For instance, given to following structure: MyProject/
We can identify 3 projects. Gradle will reference them with the following name:
The :app project is likely to depend on the libraries, and this is done by declaring the following dependencies: dependencies { compile project(':libraries:lib1') } |
|||||||||
|
|
To resolve this problem, you just need to add the abs resource path to your project build file, just like below:
So, I again compile without any errors. |
||||
|
|
|
The easiest way I found to include external library project is (for example to include facebook lib which stored one directory up in 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 sync project with gradle files |
|||
|
|
|
If you have Android Studio .0.4.0, you can create a new folder in your build path, |
||||
|
|
|
This is the dropbox link of how to Add jar File and Library Project in latest Version of Android Studio 1.0.1. Please see the doc with screenshots its very easy for new user. https://www.dropbox.com/s/1e3eteu3h0pmkf7/Android%20studio%20_doc.doc?dl=0 |
||||
|
|
|
Hi, lazy guys like me ;) Here is solution for Android Studio 1.0 |
||||
|
|
|
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).
|
||||
|
|
|
very old question but I had a different cause of the problem so for peaple:
change mavenCentral() to jcenter() and add
|
|||
|
|
|
An example of succesfully adding another library (PullToRefresh). Also works for ABS libproject. |
|||
|
|
|
open build gradle module app file and add your dependency if you download library just import and build as gradle other wise add repositories in side gradle module app
first repositories will download library for you add compile the downloaded library
If you are created a library you just need to import the project as import new module |
|||
|
|
Thank you for your interest in this question.
Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.
Would you like to answer one of these unanswered questions instead?
Gradle, see this StackOverflow answer. – craned Oct 16 '14 at 19:55