Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle can't find dependency (Android support library)

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?

like image 847
Peter Fortuin Avatar asked May 21 '13 15:05

Peter Fortuin


People also ask

Where can I find dependencies in Android Studio?

Go to File > Project structure in Android Studio. Select the app module in the Modules list on the left. Select the Dependencies tab.


1 Answers

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.)

like image 169
Peter Niederwieser Avatar answered Sep 27 '22 21:09

Peter Niederwieser