android – How to import Action Bar Sherlock to gradle project?-ThrowExceptions

Exception or error:

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.
How to solve:

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

###

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

###

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.

Leave a Reply

Your email address will not be published. Required fields are marked *