Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
689 views
in Technique[技术] by (71.8m points)

maven - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...