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.)
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).
E.g.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.0'
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).
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):
In settings.gradle add
include ':facebook'
project(':facebook').projectDir = new File(settingsDir, '../dependencies/FacebookSDK')
In build.gradle dependencies section, add
compile project ('facebook')
All left to do is synchronise the project with gradle files.
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')
...
}
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.
First Way This is working for MacBook.
First select your builder.gradle file as given screen:
Add dependencies like as on the selected screen:
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...:
After clicking on Import Module,
give the path of library like as my MacBook path:
Click on Finish. Now your library are added.
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).