Android Studio gradle and libraries import

Bresiu picture Bresiu · Aug 8, 2013 · Viewed 15.6k times · Source

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?

Answer

shakalaca picture shakalaca · Sep 6, 2013

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