23

I've imported Module to Android Studio using steps posted this question: Problems importing project into Android Studio regarding ActionBarSherlock

The IDE is working well, but It doesn't affect the build. From Android Studio: Are Library Project dependencies picked from project.properties?

If you use Gradle, project.properties is completely ignored. You should not use the Module Settings to add dependencies now as it only changes the IDE but not the Gradle based build system (we'll fix this in later versions).

I've modified dependencies of build.gradle

dependencies {
    compile files('libs/android-support-v4.jar')
    compile project(":ActionBarSherlock")
}

But it build prints different error now: Gradle:

FAILURE: Build failed with an exception.
* Where:
Build file '...PATH.../PROJECT_NAME/PROJECT_NAME/build.gradle' line: 13
* What went wrong:
A problem occurred evaluating project ':PROJECT_NAME'.
> Project with path ':ActionBarSherlock' could not be found in project ':PROJECT_NAME'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Community
  • 1
  • 1
kravemir
  • 10,636
  • 17
  • 64
  • 111

3 Answers3

23

THIS ANSWER IS DEPRICATED: Please check out AppCompat as a replacement!

dependencies {
    compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
    compile 'com.android.support:support-v4:18.0.+'
}

Found that on the ActionBarSherlock site and ActionBar Sherlock with Android Studio 0.2.2

ABS has released their aar.

Also a sample using it on github:

https://github.com/JakeWharton/ActionBarSherlock-Gradle-Sample

The support library version number is not critical make sure you always use the most up to date version permitted by your project. The actual inclusion of the support jar as a whole is NOT optional

Community
  • 1
  • 1
Dan Sabin
  • 896
  • 1
  • 9
  • 14
  • I thought one needs settings.gradle? – IgorGanapolsky Oct 07 '13 at 02:53
  • This is also now recommended on the [ActionBarSherlock](http://actionbarsherlock.com/usage.html) site. – Graham Borland Jan 14 '14 at 11:06
  • Don't know why but I'm getting error: Could not find com.actionbarsherlock:actionbarsherlock:4.4.0. and I have reference to the maven repository: repositories { mavenCentral() } – petrsyn Mar 05 '14 at 23:28
  • Version 4.4.0 may have changed. The usages aren't updated on their website. What is the error you're seeing? – Dan Sabin Mar 06 '14 at 02:51
  • @petrsyn, you can download ABS aar and install it to your Maven repository with this command: `mvn install:install-file -Dfile=actionbarsherlock-4.4.0.aar -DgroupId=com.actionbarsherlock -DartifactId=actionbarsherlock -Dversion=4.4.0 -Dpackaging=aar` – Igor K Oct 01 '14 at 20:48
11

Just a notice: at the moment proper support for importing external libraries that include resources (aar library files) does not seem to be supported properly yet. It is the reason why ActionBarSherlock is not yet releasing their project as an aar file. However if you put the code of the external library (ActionBarSherlock) in the directory of your project it should be able to work.

Now, to get multiple projects working create a file called 'settings.gradle' in the root of your project and put the following lines in there:

include 'actionbarsherlock'
include 'yourproject'

Now make sure you have the two subdirectories in the same folder as gradle.settings: actionbarsherlock and yourproject. In those subdirectories should be the build file (build.gradle) and the rest of your project. The structure should be something like this:

Project
|-- settings.gradle
|-- actionbarsherlock
|   |-- build.gradle
|   |-- AndroidManifest.xml
|   |-- src
|   |   `-- *
|   |-- res
|   |   `-- *
|   `-- ...
`-- yourproject
    |-- build.gradle
    `-- src
        `-- main
            |-- AndroidManifest.xml
            |-- java
            |   `-- *
            `-- res
                `-- *

Hopefully that makes sense, though this is usually the way you build multiple depending projects of your own. You usually do not want the code of external libraries (like ActionBarSherlock) to be in your project-repository, but like I said, doing it properly isn't ready yet.

Also, just a notice, ActionBarSherlock's stable versions do not yet have a gradle build file. Use ActionBarSherlock's dev branch from git to get the right source files: https://github.com/JakeWharton/ActionBarSherlock/tree/dev/actionbarsherlock

MasterAM
  • 16,283
  • 6
  • 45
  • 66
FrozenCow
  • 320
  • 2
  • 6
  • Thanks :) It helped much, I've made `build.gradle` for ActionBarShelock library on my own, before I looked at github and I've learned some things about gradle build system :) – kravemir May 31 '13 at 17:06
  • Thanks. On my setup I had to edit `settings.gradle`, and add `include ':ActionBarSherlock:actionbarsherlock'` to it. I'm just mentioning this in a comment because this isn't _exactly_ what you typed. But that did help me! :) – Benoit Duffez Jun 07 '13 at 10:41
  • Ah right, ':ActionBarSherlock:actionbarsherlock' because the library project is in a subsubdirectory for you. That means you have the following structure (Bleh, comment formatting sucks): /gradle.settings /yourproject/ /ActionBarSherlock/actionbarsherlock/build.gradle – FrozenCow Jun 12 '13 at 09:27
2

I hope we can have a way of showing people that some of these libraries are deprecated.

AppCompat should now be used instead of the deprecated ActionbarSherlock.

nyxee
  • 2,773
  • 26
  • 22