Search code examples
androideclipsegradlebuild.gradlegradle-eclipse

Building Android project with Gradle failed


I'm trying from yesterday to configure gradle to build Android project. I've got same error since then:

Failed to notify project evaluation listener. Could not resolve all dependencies for configuration ':_DebugCompile'. Could not find any version that matches com.android.support:support-v4:13.0.+.

The official fix on many sites is to install Android Support Repository. I have it installed already, but problem still occurs. I've run out of ideas what can be wrong here...

Here is full code:

buildscript {
    repositories {
         mavenCentral()
     }

     dependencies {
         classpath 'com.android.tools.build:gradle:0.5+'
     }
}

apply plugin: 'android'

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

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

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

        instrumentTest.setRoot('tests')
    }
}

Solution

  • You need an additional block at the top level after your apply plugin line:

    repositories {
         mavenCentral()
     }
    

    In general, you need a repositories block at the same level as any dependencies block (hence why you also need one in the buildscript block).

    Most of the time, you'd move your buildscript block to the top level build.gradle (so that all your modules use the same gradle build) rather than have them both at the module level.