How to add Android Support Repository to Android Studio?

43

I'm using Android Studio with an external Android SDK. I have installed the support library and the support repository. The support repository is in:

~/Development/Tools/android/sdk/extras/android/m2repository

When I add a dependency to the support library in the build.gradle file, like:

...

repositories {
    mavenCentral()
}

...

dependencies {
   compile "com.android.support:support-v4:18.0.+"
}

Android Studio cannot find the support libraries (cannot resolve symbol etc) and Gradle also cannot find the libraries:

Gradle: A problem occurred configuring project ':TestAndroidStudio'.
> Failed to notify project evaluation listener.
   > Could not resolve all dependencies for configuration ':TestAndroidStudio:_DebugCompile'.
      > Could not find any version that matches com.android.support:support-v4:18.0.+.
        Required by:
            TestAndroidStudio:TestAndroidStudio:unspecified

How do I specify in Android Studio and/or the build.gradle file the location of the Android support repository?

This question is tagged with android gradle android-studio android-support-library android-gradle-plugin

~ Asked on 2013-11-13 15:48:19

The Best Answer is


28

You are probably hit by this bug which prevents the Android Gradle Plugin from automatically adding the "Android Support Repository" to the list of Gradle repositories. The work-around, as mentioned in the bug report, is to explicitly add the m2repository directory as a local Maven directory in the top-level build.gradle file as follows:

allprojects {
    repositories {
        // Work around https://code.google.com/p/android/issues/detail?id=69270.
        def androidHome = System.getenv("ANDROID_HOME")
        maven {
            url "$androidHome/extras/android/m2repository/"
        }
    }
}

~ Answered on 2014-08-18 14:11:35


26

Gradle can work with the 18.0.+ notation, it however now depends on the new support repository which is now bundled with the SDK.

Open the SDK manager and immediately under Extras the first option is "Android Support Repository" and install it

~ Answered on 2013-11-25 18:46:45


Most Viewed Questions: