5

I have successfully imported ActionBarSherlock to my project, and need to import another two libraries: Sliding Layer and Crouton. I know that similar questions have already appeared here before, but I've tried almost everything, each time breaking something in the project in a way that I had to start over.

My project tree looks like:

MyProject/
+ app/
+ libraries/
   + actionbarsherlock/
   + crouton/
   + slidinglayer/

I imported those two libraries as modules (File->Import Module)

My setting.gradle file looks like it should:

include ":libraries:actionbarsherlock", ':Krypto', ':libraries:crouton', ':libraries:slidinglayer'

actionbarsherlock gradle:

buildscript {
    repositories {
        maven { url 'http://repo1.maven.org/maven2' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}
apply plugin: 'android-library'

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

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 16
    }

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            res.srcDirs = ['res']
        }
    }
}

app gradle:

buildscript {
    repositories {
        maven { url 'http://repo1.maven.org/maven2' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}
apply plugin: 'android'

dependencies {
    compile project(":libraries:actionbarsherlock")
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 16
    }
}

slidinglayer gradle:

apply plugin: 'android-library'

dependencies {
    compile "com.android.support:support-v4:18.0.0"
}

android {
    compileSdkVersion 18
    buildToolsVersion "18.0.1"

    defaultConfig {
        minSdkVersion 4
        targetSdkVersion 18
    }

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            res.srcDirs = ['res']
        }
    }
}

In crouton folder there is no gradle.build file. How it should look like? Theres only java files (no resources).

How to set up correctly dependencies in crouton and slidinglayer libraries?

Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
Bresiu
  • 2,123
  • 2
  • 19
  • 31

2 Answers2

5

build.gradle for crouton

buildscript {
    repositories {
        maven { url 'http://repo1.maven.org/maven2' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}

apply plugin: 'android-library'

dependencies {
    compile 'com.android.support:support-v4:18.0.0'
}

android {
    compileSdkVersion 18
    buildToolsVersion "18.0.1"

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 17
    }

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
        }
    }
}

and in your app build.gradle, change

dependencies {
    compile project(":libraries:actionbarsherlock")
}

to

dependencies {
    compile project(":libraries:actionbarsherlock")
    compile project(":libraries:crouton")
    compile project(":libraries:slidinglayer")
}

and import again in Android Studio

shakalaca
  • 1,692
  • 12
  • 5
1

I don't know how to solve your problem, but when I faced problem of third party library use in Gradle build, I solved by following way.

Following is my structure of project.

GsonDemoProject
   GsonDemo
      build
      libs
          android-support-v4.jar
          gson.jar
      src
          main
          build.gradle
      build.gradle
      settings.gradle

I edited my build.gradle file which resides in src directory.

dependencies {
    compile files('libs/android-support-v4.jar','libs/gson.jar')
}

I put reference of 3rd party library in dependencies tag like above. In my project libs is directory where libraries are put.

Chintan Rathod
  • 25,864
  • 13
  • 83
  • 93
  • I've tried to add crouton library to 'actionbarsherlock/libs' and add 'libs/crouton' to build.gradle, as you suggested - still with errors. Also, I've tried similar idea with adding 'compile files' to dependiences in app build.gradle - still with no results. – Bresiu Aug 08 '13 at 14:22
  • @Bresiu, are your libraries inside `libs` directory? try `compile files('libs/android-support-v4.jar','libs/actionbarsherlock.jar','libs/crouton.jar')`. As you can see in code, `.jar` is compulsory. :) – Chintan Rathod Aug 08 '13 at 14:25
  • These libraries are not .jars. These are normal projects mark as libraries. I've tried to adding it to libs folder inside actionbarsherlock as I said, and in second try, I've tried to paste libraries inside apps libs folder. Without success. I don't understand these gradle things. Only library I succesfully imported was actionbarsherlock with this tutorial: http://stackoverflow.com/a/16639227/1888738 with some changes given in comments. – Bresiu Aug 08 '13 at 14:38