Gradle can't find dependency (Android support library)

29,773

Solution 1

You have declared a repository dependency, but haven't declared a repository. Hence the dependency cannot be resolved. (Repositories/dependencies in the buildscript block are strictly separated from repositories/dependencies in the main build script.)

Solution 2

http://pastebin.com/FmcCZwA5

This paste is elaborate project with AndroidAnnotations, Dagger, Jackson and Robolectric.

all you need is add

repositories {
    mavenCentral()
}

replace

 compile group: 'com.google.android', name: 'support-v4', version: 'r7'

with (line 44 of the code linked above)

 compile 'com.android.support:support-v4:18.0.+'

Gotchas: Last bit will works on Android Studio 0.2+ only if you had a fresh install. Since 0.2 Studio is shipped with its internal m2 repo to provide support and google api libraries so if you upgraded from previous versions your SDK doesn't have it.

also make sure local.properties file is present in root folder and sdk.dir points to SDK

Solution 3

You need to add additional dependency in dependencies tag. If you have android-support-v4.jar library in your libs folder, try to add code listed below:

dependencies {
    compile files('libs/android-support-v4.jar')
}
Share:
29,773
Peter Fortuin
Author by

Peter Fortuin

I'm a Android developer!

Updated on September 02, 2020

Comments

  • Peter Fortuin
    Peter Fortuin almost 4 years

    I have a problem that Gradle can't find my dependency (Android support library).

    My build.gradle looks like this:

    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:0.4'
        }
    }
    apply plugin: 'android'
    
    dependencies {
        compile files('libs/FlurryAgent.jar')
        compile group: 'com.google.android', name: 'support-v4', version: 'r7'
        compile files('libs/YouTubeAndroidPlayerApi.jar')
    }
    
    android {
        compileSdkVersion 17
        buildToolsVersion "17"
    
        defaultConfig {
            minSdkVersion 11
            targetSdkVersion 17
        }
        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')
        }
    }
    

    When I build (on commandline, no IDE) I get the following message:

    FAILURE: Build failed with an exception.
    
    * What went wrong:
    A problem occurred configuring root project 'AndroidCalculator'.
    > Failed to notify project evaluation listener.
       > Could not resolve all dependencies for configuration ':compile'.
          > Could not find com.google.android:support-v4:r7.
            Required by:
                :AndroidCalculator:unspecified
    
    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
    
    BUILD FAILED
    

    Why am I not allowed to add the Android Support library like this?

  • srgblnch
    srgblnch about 11 years
    Specifically, add this as a root item to your build.gradle: repositories { mavenCentral() } Details: jayway.com/2013/02/26/…
  • IgorGanapolsky
    IgorGanapolsky over 10 years
    I don't think one needs to put this jar into their libs folder explicitly. That was the old way of doing things in Eclipse. Instead, Gradle and Android studio will now fetch the latest support library and package it in your project automatically if you add the 'compile' dependency.
  • Herman Junge
    Herman Junge about 8 years
    You sir, are the real MVP