1

I have some build.gradle file this

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

apply plugin: 'android'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile 'com.github.chrisbanes.actionbarpulltorefresh:library:+'
}

android {
    compileSdkVersion 18
    buildToolsVersion '18'

    defaultConfig {
        targetSdkVersion 18
    }

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

that throws this error :

A problem occurred configuring root project 'NewsFeeder'.
> Failed to notify project evaluation listener.
   > Could not resolve all dependencies for configuration ':_DebugCompile'.
      > Could not find any version that matches com.github.chrisbanes.actionbarpulltorefresh:library:+.
        Required by:
            :NewsFeeder:unspecified

But, this reference to chrisbanes's actionbarpulltorefresh seems to be correct : https://github.com/chrisbanes/ActionBar-PullToRefresh/wiki/QuickStart-Stock. How can it be since in this project is available in [maven central repo][1] ?

For information, I set in some local.propertiesfile sdk.dir=/home/adt-bundle-mac-x86_64-20130522/sdk, which is the same that what echo $ANDROID_SDK returns

user1611830
  • 4,749
  • 10
  • 52
  • 89

1 Answers1

1

You need to tell gradle where it can look to find the dependency. If you want gradle to use the mavenCentral repository then add this to your build.gradle file:

repositories {
    mavenCentral()
}

The buildscript repositories is just for the build script dependencies, not project dependencies. You want to add the repositories entry at the outer most, or project, level.

Your build.gradle would look like:

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

apply plugin: 'android'

repositories {
    mavenCentral()
}

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile 'com.github.chrisbanes.actionbarpulltorefresh:library:+'
}

android {
    compileSdkVersion 18
    buildToolsVersion '18'

    defaultConfig {
        targetSdkVersion 18
    }

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            res.srcDirs = ['res']
        }
    }
}
ditkin
  • 6,774
  • 1
  • 35
  • 37
  • But it is put on the top of the file. Should I wrap it there ? – user1611830 Jan 23 '14 at 21:56
  • Put another repositories entry right above the dependencies entry. See http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html – ditkin Jan 23 '14 at 21:58
  • Now, everything works perfectly, but I can't access any class from the `actionbarpulltorefresh` project. Indeed, `import uk.co.senab.actionbarpulltorefresh.library.PullToRefreshLayout;` is not recognized. How can I handle this ? Where the `actionbarpulltorefresh` files are stored ? – user1611830 Jan 23 '14 at 22:38
  • Is not recognized in the IDE that you are using or not recognized when doing a build at the command line? Gradle caches stuff in .gradle/caches/ in your home directory. – ditkin Jan 23 '14 at 22:44
  • ..."Is not recognized by the IDE". In fact I don't have any `caches` directory in my `.gradle` directory. – user1611830 Jan 23 '14 at 22:50
  • You may be running into http://stackoverflow.com/questions/21100688/android-studio-0-4-2-suddenly-cannot-resolve-symbols/21100896#21100896 – Scott Barta Jan 24 '14 at 04:26
  • @user1611830 Can you access the class in the library finally? – penkzhou Aug 28 '14 at 06:53