Hesam
Hesam

Reputation: 53600

How to hardcode actual path to a maven repository in Gradle, Android?

I have an strange issue. I just pulled our master branch and I am the only developer who get following error message among many Android developers in my company.

FAILURE: Build failed with an exception.

* What went wrong:
Could not resolve all files for configuration ':bookingcore-android:debugCompileClasspath'.
> Could not find play-services-ads-identifier.jar (com.google.android.gms:play-services-ads-identifier:15.0.1).
  Searched in the following locations:
      https://dl.google.com/dl/android/maven2/com/google/android/gms/play-services-ads-identifier/15.0.1/play-services-ads-identifier-15.0.1.jar

we have following in root build.gradle file

repositories {
        google()
        jcenter()
        ...
}

and in one of our modules:

plugins {
    id 'com.android.library'
    id 'kotlin-android'
    id 'kotlin-android-extensions'
}
dependencies { 
    ....
    implementation "com.google.android.gms:play-services-ads-identifier:15.0.1"
}

Based on my search, actual maven path to play-services-ads-identifier.jar is https://mvnrepository.com/artifact/com.google.android.gms/play-services-ads-identifier/15.0.1. Is there anyway to tell gradle to download play-services-ads-identifier.jar from this link rather than google maven?

Upvotes: 1

Views: 518

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006914

Based on my search, actual maven path to play-services-ads-identifier.jar is https://mvnrepository.com/artifact/com.google.android.gms/play-services-ads-identifier/15.0.1

No, that is a Web page. Among other things, it contains:

Note: this artifact it located at Google repository (https://maven.google.com/)

On my Android Studio 3.1.4 installation, like your coworkers, I am having no problems with:

implementation "com.google.android.gms:play-services-ads-identifier:15.0.1"

when I have google() listed in allprojects { repositories {} } in the root build.gradle.

For some reason, your Android Studio seems to think that this is a JAR, when it is really an AAR.

Tactically, you can force the issue, by changing the line to:

implementation "com.google.android.gms:play-services-ads-identifier:15.0.1@aar"

However, that is treating a symptom, not whatever the underlying problem is.

If you want to try fixing the underlying problem, try these:

  1. If you have not done so already, do Build > Clean Project, and see if it picks up the AAR (I doubt that this helps, but it's always a good first step)
  2. If that does not help, try File > Invalidate Caches/Restart, and see if it then picks up the AAR
  3. You can try to clear the build cache if you are using Gradle 3.3 or higher, then see if it picks up the AAR
  4. If that does not help, you can try closing Android Studio, renaming ~/.gradle/caches (or the equivalent on Windows) to something else, re-opening Android Studio, and seeing if it then picks up the AAR as it re-downloads all of your dependencies (if this works, you can delete the renamed directory; if it fails, you can always restore the renamed directory)

Upvotes: 3

Related Questions