11

For some unknown reason Gradle is refusing to download every dependancy that I put in my gradle.build file. I'm trying to get the 'me.dm7.barcodescanner:zbar:1.7' dependancy but every time I try to sync my gradle it just gives me the following error:

Error:(6, 13) Failed to resolve: me.dm7.barcodescanner:zbar:1.7

It's not just the zbar library either, it's every library this isn't a com.android library. I'm not in offline mode so that can't be it either. Is there something wrong in my .build file?

apply plugin: 'com.android.application'

dependencies {
    compile fileTree(include: '*.jar', dir: 'libs')
    compile project(':MetaioSDK')
    compile 'com.android.support:support-v4:22.0.0'
    compile 'me.dm7.barcodescanner:zbar:1.7'
}

android {
    compileSdkVersion 19
    buildToolsVersion "21.1.0"

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

        // 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')
    }
}

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.0'
    }
}
Per Lundberg
  • 3,837
  • 1
  • 36
  • 46
Anubis
  • 1,162
  • 4
  • 14
  • 31

2 Answers2

13

Alright, managed to fix it. Added this inside the dependencies block:

repositories {
    mavenCentral()
}
Anubis
  • 1,162
  • 4
  • 14
  • 31
  • 2
    Actually a more appropriate location for the repositories block would be at the global script scope and not inside the dependencies block - find more details [here](http://gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html). – Amnon Shochot May 01 '15 at 09:29
3
    buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.1'
    }
}
apply plugin: 'android'
repositories {
    mavenCentral()
}
dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile 'me.dm7.barcodescanner:zbar:1.7'
}

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

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

        instrumentTest.setRoot('tests')
    }
}

Put repository block independently from from other blocks

sanevys
  • 559
  • 1
  • 7
  • 27