1

In the 3rd answer here: How do I add a library project to Android Studio? I found informations about how we can add ABSherlock library to project using gradle in Android Studio. But in this way we use "import module" option which doesn't exist any more in Android Studio 0.4.0. So how should I add ABSherlock or other library now ? (using gradle)

Community
  • 1
  • 1
Mkr
  • 428
  • 2
  • 5
  • 16

1 Answers1

2

You can add this part to your build.gradle script

dependencies {
    compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
}

EDIT: If you are using also the support library you can use it:

dependencies {      
    compile 'com.android.support:support-v4:19.0.0'
    compile ('com.actionbarsherlock:actionbarsherlock:4.4.0@aar'){
        // Need to specifically exclude this as it is specified in ActionBarSherlock pom
        exclude group: 'com.google.android', module: 'support-v4'
    }
}

EDIT2: If you would like to work with abs with a local copy ( I suggest you to use the maven dependency ) you can do this:

-root
 -lib
   -abs
     build.gradle
     src
     res
 -myModule
     build.gradle
 settings.gradle

In settings.gradle:

include ':myModule', ':lib:abs'

In lib/abs/build.gradle:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.7.+'
    }
}
apply plugin: 'android-library'

android {

   compileSdkVersion 19
   buildToolsVersion "19.0.0"

   defaultConfig {
       minSdkVersion XX
       targetSdkVersion 19

   }    

   sourceSets {
            main {
                manifest.srcFile 'AndroidManifest.xml'
                java.srcDirs = ['src']
                resources.srcDirs = ['src']            
                res.srcDirs = ['res']            
            }
        }
    }
}
dependencies {      
    compile 'com.android.support:support-v4:19.0.0'      
}

Remove the supportV4.jar from your local abs library.

In myModule/build.gradle you should add:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.7.+'
    }
}
apply plugin: 'android'

android {

   compileSdkVersion 19
   buildToolsVersion "19.0.0"

   defaultConfig {
       minSdkVersion XX
       targetSdkVersion 19
     }

   }    
    dependencies {
        // Libraries
        compile project(':lib:abs')  
      }

If in myModule/build.gradle you need to use the support library, you should add:

dependencies {
   compile 'com.android.support:support-v4:19.0.0'
    // Libraries
    compile project(':lib:abs')  
  }

Working with gradle you should prefer to use dependencies in Maven. However you can use local libraries with this structure above, editing your gradle files.

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
  • I've tried it but I got error which say that some things are already defined. I think that it could be a problem with android-support-v4 library, which you usually should delete from your project during using ABS in Eclipse (in "normal" way). But what should I delete here in Android Studio if I use gradle? (and I dont have any .jars) – Mkr Dec 23 '13 at 14:26
  • Your answer doesn't contain exactly what I wanted, I needed this:
    dependencies { compile project(':actionbarsherlock') }
    and I got it after hours fight with project import, but you was close so I accepted ur answer :).
    – Mkr Dec 27 '13 at 15:45
  • I've updated again the answer. I suggest you the best way, also I suggest the code to use in gradle files, to use a local library. It works with abs, but you can use it with other libraries. – Gabriele Mariotti Dec 27 '13 at 16:05
  • That's exactly what I want to know. Thanks a lot. By the way: I never use Maven or Ant before and as I see that's my main problem, but I'll try... :). – Mkr Dec 27 '13 at 16:54