47

suddenly gradle is unable to build the same code that was working moments ago ! my project depends on google play service dependencies

it says :

Could not find play-services-basement.aar (com.google.android.gms:play-services-basement:15.0.1). Searched in the following locations: https://jcenter.bintray.com/com/google/android/gms/play-services-basement/15.0.1/play-services-basement-15.0.1.aar

I think the aar file was removed from google by mistake

Does anyone have any idea, what is going on?

Ahmed Ali
  • 785
  • 1
  • 8
  • 15
  • Possible duplicate of [Failed to resolve: recyclerview-v7](https://stackoverflow.com/questions/50891617/failed-to-resolve-recyclerview-v7) – Radesh Oct 23 '18 at 15:16

3 Answers3

102

Add google() repository in your build.gradle. And check that google() is before jcenter().

Jivy
  • 1,213
  • 1
  • 10
  • 10
  • I checked out the git commit that I was building the whole day. why now it stops working – Ahmed Ali Oct 23 '18 at 12:23
  • 8
    wow. No idea why it worked (putting google() before jcenter() ). I've been using this configuration for a few years now(!) – guy_m Oct 23 '18 at 13:27
  • 12
    Google (or Jcenter) suddenly deletes play services from Jcenter, but only the artifacts, not the dependency, so when Gradle check dependency in Jcenter, it is ok but the download failed and the build fails. Putting google() before jcenter() and Gradle will check play services dependencies in google before jcenter, and the Google repository seems correct – Jivy Oct 24 '18 at 13:22
  • @Jivy, you should edit the answer with this valid information! – Borzh Oct 26 '18 at 00:51
  • thanks , I have facing issue but your solution is working – Tarun Umath Oct 26 '18 at 14:28
  • Actually it does work but I had to change my top level build.gradle to also have google above jcenter – Carson Holzheimer Oct 27 '18 at 07:10
  • I had both, but I moved google above jcenter and it appears to have fixed the issue for me. That's a heck of a quirk, thanks for calling out the ordering! – ima747 Nov 06 '18 at 15:28
  • I would suggest putting google() at the very top. I had maven included as a repository too and i had to put google above that to make it work – passatgt Nov 15 '18 at 13:48
21

The problem seems to be with jcenter. I have spent hours together with this problem and your problem seems to be similar to mine and I think the following solution should work.

For some reason and for many libraries in jcenter, the pom files of many libraries are kept in place but corresponding aar files have been removed. This is also the case with play-services-basement library. Check the following here for reference ( pom file of play-services-basement is available at jcentre here but aar file is not available at jcentre here):

Solution : In your project level gradle file , change the following block of code

allprojects {
    repositories {
        jcenter()
        google()
    }
}

to

allprojects {
    repositories {
        google()
        jcenter()
    }
}

why this works ?

In our first code block, when gradle tries to resolve a dependency in the repository(in my case,it was google-services-basement in jcentre repository), it ddi not get resolved as corresponding aar files has been removed. As a result , build fails with something like :

 Could not find play-services-basement.aar (com.google.android.gms:play-services-basement:15.0.1).

In our second code block, google repository has been referenced before jcenter repository. When gradle build starts, it looks first in the libraries listed first in repositories{... for resolving any library that is used in the project. Now, when gradle tries to resolve play-services-basement in jcenter, it is successful in resolving dependency as corresponding aar file has been made available by google repository(the same aar file of latest version is not available in jcenter repository) which has been referenced before jcenter repository is assessed. Do check and let me know if that works.

Abhishek Luthra
  • 2,575
  • 1
  • 18
  • 34
0

IN Worked

allprojects {
repositories {
    google()
    jcenter()
    maven {
        url 'https://jitpack.io'
    }
    maven {
        url 'https://maven.google.com'
    }

}