Search code examples
androidandroid-studiocardslib

Add Cardslib library To Android Studio 0.8.1


This is my first project using Android Studio so spare me if you find this question naive. I am trying to include the Cardslib library to my project in Android Studio (version 0.8.1). Initially I tried to include it by adding the following line in build.gradle:

compile 'com.github.gabrielemariotti.cards:library:1.7.3'

But it returned the following error (upon sync)

Error:Failed to find: com.github.gabrielemariotti.cards:library:1.7.3

The I tried to include the jar file by,

  1. Downloading it from maven repository
  2. Adding jar file to libs folder.
  3. Adding following line in build.gradle

compile files('libs/library-1.7.3-sources.jar')`

Though gradle project sync without any error but I am not able to create simple cards i.e still not working for me.

I wanted the first method to work since Android Studio would then handle everything but I guess I am doing something horribly wrong.

[Edit] - Adding the build.gradle code

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

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile 'com.github.gabrielemariotti.cards:library:1.7.3'
}

android {
    compileSdkVersion 19
    buildToolsVersion '20.0.0'

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

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

Solution

  • Add this block in your script to tell gradle where it can find the repo with libs.

    repositories {
        mavenCentral()
    }
    

    So your script will be something like this:

       ....... 
       apply plugin: 'android'
    
           repositories {
                mavenCentral()
            }
    
    
        dependencies {
            compile fileTree(dir: 'libs', include: '*.jar')
            compile 'com.github.gabrielemariotti.cards:library:1.7.3'
        }
    .......