Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Gradle build fails: Could not find com.google.android:support-v4:r18

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?

like image 636
Nimrod Dayan Avatar asked Sep 01 '13 15:09

Nimrod Dayan


4 Answers

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

like image 71
madhead - StandWithUkraine Avatar answered Oct 22 '22 08:10

madhead - StandWithUkraine


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

like image 42
robotoaster Avatar answered Oct 22 '22 08:10

robotoaster


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

to download exactly support library

like image 2
Yunfei Tang Avatar answered Oct 22 '22 06:10

Yunfei Tang


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.

like image 2
Vladimir Ryhlitskiy Avatar answered Oct 22 '22 08:10

Vladimir Ryhlitskiy