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

Exception or error:

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?

How to solve:

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

###

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

###

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.

###

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

to download exactly support library

Leave a Reply

Your email address will not be published. Required fields are marked *