20

EDIT:

This issue seemed to disappear by its own somehow, possibly due to the new Gradle build system becoming more mature.

I have two separate Android projects:

The 1st project is an Android Library using 'android-library' plugin for Gradle, which depends on the support-library-v4:r18. Snippet from dependencies in build.gradle:

compile 'com.android.support:support-v4:18.0.0'

The support library is fetched from Android Support Repository installed via Android SDK Manager as explained here. This project is then built and published to maven local repository by running: gradle uploadArchives

I verified and indeed the library .aar is then available under the local maven repository.

The 2nd project is an Android app using 'android' plugin for Gradle, which references the maven dependency of the library produced by the first project. Here is a snippet from build.gradle:

repositories {
    mavenLocal()
    mavenCentral()
}
dependencies {
    compile 'com.android.support:support-v4:18.0.0'
    compile 'com.example:cool-lib:1.0.0-SNAPSHOT'
}

NOTE: The two projects are completely separated from another. Meaning that, they are NOT subprojects of the same root project.

When I try to build the 2nd project by running: gradle assemble

I get the following error:

Could not find com.google.android:support-v4:r18.
Required by:
    com.example:app-project:unspecified > com.example:cool-lib:1.0.0-SNAPSHOT

I checked the .pom file of cool-lib, under my local maven repo folder and I saw that it has the following dependency:

<dependency>
  <groupId>com.android.support</groupId>
  <artifactId>support-v4</artifactId>
  <version>18.0.0</version>
  <scope>compile</scope>
</dependency>

For some reason, Gradle is trying to get the support library-v4 r18 for the lib-project from maven central repository instead of getting it from Android Support Repository. It fails since the latest version in Maven Central of the support-library-v4 is r7.

Is there a way to force Gradle to strictly fetch the support-library-v4 r18 from Android Support Repository also for external Android libraries which are referenced from Maven Central?

Community
  • 1
  • 1
Nimrod Dayan
  • 3,050
  • 4
  • 29
  • 45
  • I am also seeing the issue when using two libraries, one of which requires the other one. Have you been able to fix it? – frapontillo Feb 21 '14 at 17:11
  • I had the same error when my ANDROID_HOME environment variable was pointing to an old version of the SDK – Jared Kells Feb 27 '15 at 12:23

4 Answers4

38

You need to install Android Support Repository from SDK manager. After that Gradle will be able to resolve support libraries from ${SDK_HOME}\extras\android\m2repository\.

madhead
  • 31,729
  • 16
  • 153
  • 201
  • I had to do this after upgrading the SDK (following Android L release) – Marco Ferrari Jul 12 '14 at 13:54
  • As written in the question: `The support library is fetched from Android Support Repository installed via Android SDK Manager as explained here`, implying that I already had it installed. This issue seemed to disappear by its own somehow, possibly due to the new Gradle build system becoming more mature. – Nimrod Dayan Mar 11 '15 at 15:42
  • Is there a way to install the support repository from the command line? – martinkunev Dec 13 '17 at 19:52
  • @martinkunev, take a look at https://stackoverflow.com/q/23436564/750510 – madhead Dec 13 '17 at 23:46
6

make sure you have your local.properties file in main project folder and sdk.dir variable is pointing to Android SDK. (tested on mac)

robotoaster
  • 3,082
  • 1
  • 24
  • 23
  • 1
    I have ANDROID_HOME environment variable set for that purpose, I think it has the same affect according to my understanding... – Nimrod Dayan Sep 09 '13 at 18:39
  • I might be wrong but it depends where ANDROID_HOME is set. Is it set in .bashrc or .bash_profile? If so it is visible only in terminal but not from desktop. e.g. for gnome it will be somewhere else. – robotoaster Sep 10 '13 at 10:53
  • `ANDROID_HOME` serves the same purpose as settings `sdk.dir`. – Flow Jan 16 '14 at 12:28
2

You need to install Android Support Repository as madhead says. But in my case it was absent. You should go to the Tools->Manage Add-on Sites... and check all "Google Inc." sites. Then Android Support Repository will appear in the packages list, and you can install it.

2

refer to: https://github.com/simpligility/maven-android-sdk-deployer

to download exactly support library

Yunfei Tang
  • 496
  • 2
  • 6
  • 11