0

I've got a gradle project that contains my app and then my lib. I'm seeing errors when trying to build my app module because it can't find the dependencies needed by the lib module.

* What went wrong:
Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
Could not find com.google.android.gms:play-services-location:11.4.2.
Searched in the following locations:
  file:/Users/me/Library/Android/sdk/extras/m2repository/com/google/android/gms/play-services-location/11.4.2/play-services-location-11.4.2.pom
  file:/Users/me/Library/Android/sdk/extras/m2repository/com/google/android/gms/play-services-location/11.4.2/play-services-location-11.4.2.jar
  file:/Users/me/Library/Android/sdk/extras/google/m2repository/com/google/android/gms/play-services-location/11.4.2/play-services-location-11.4.2.pom
  file:/Users/me/Library/Android/sdk/extras/google/m2repository/com/google/android/gms/play-services-location/11.4.2/play-services-location-11.4.2.jar
  file:/Users/me/Library/Android/sdk/extras/android/m2repository/com/google/android/gms/play-services-location/11.4.2/play-services-location-11.4.2.pom
  file:/Users/me/Library/Android/sdk/extras/android/m2repository/com/google/android/gms/play-services-location/11.4.2/play-services-location-11.4.2.jar

Required by:
  project :app > project :lib

This error is duplicative for all of the lib module's dependencies. I currently have these dependencies defined in lib/build.gradle under the repositories.

repositories {
    jcenter()
    google()
    maven { url "https://jitpack.io" }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.google.android.gms:play-services-location:11.4.2'
    implementation 'com.google.android.gms:play-services-gcm:11.4.2'
    // ...
}
// ...

When I run ./gradlew lib:assembleDebug I get a success message that the lib has built. So I know that the repositories/dependencies definitions are correct for that module. Unfortunately building the app doesn't get the desired results:

./gradlew assembleDebug --rerun-tasks --console plain
:buildSrc:compileJava NO-SOURCE
:buildSrc:compileGroovy
:buildSrc:processResources NO-SOURCE
:buildSrc:classes
:buildSrc:jar
:buildSrc:assemble
:buildSrc:compileTestJava NO-SOURCE
:buildSrc:compileTestGroovy NO-SOURCE
:buildSrc:processTestResources NO-SOURCE
:buildSrc:testClasses UP-TO-DATE
:buildSrc:test NO-SOURCE
:buildSrc:check UP-TO-DATE
:buildSrc:build
The CompileOptions.bootClasspath property has been deprecated and is scheduled to be removed in Gradle 5.0. Please use the CompileOptions.bootstrapClasspath property instead.
:app:customTask
:app:preBuild
:lib:preBuild UP-TO-DATE
:lib:preDebugBuild UP-TO-DATE
:lib:checkDebugManifest
:lib:processDebugManifest
:app:preDebugBuild FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
> Could not find com.google.android.gms:play-services-location:11.4.2.
// ... 

I do have some tasks in the app module that I inject before the preBuild task. I don't think this is causing things to be thrown off but I'll mention it just in case.

If anyone has any suggestions on implementing a multi-project gradle app where a subproject defines its own repositories I'd be very thankful.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
atreat
  • 4,243
  • 1
  • 30
  • 34
  • try to use api instead of implementation in your project for importing your lib – Fakher Dec 15 '17 at 09:20
  • After reading the docs it I think I'm supposed to be using api for this instead of implementation, unfortunately it doesn't seem to change the error. – atreat Dec 15 '17 at 17:32
  • I've crossposted this issue on the gradle forums with a sample project that exemplifies the behavior. https://discuss.gradle.org/t/project-requires-same-repositories-defined-as-library-module/25145 – atreat Dec 18 '17 at 15:34

0 Answers0