151

Yesterday I tried building my app and everything worked fine.

Today, without any changes to the project... All of a sudden I'm greeted with this warning message telling me:

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

Is anyone experiencing the same sort of issue?

If you follow the link where it's searching for the package it basically gets downloaded instantly through the browser. I suppose something has changed on the server side? Perhaps naming conventions?

It looks like it's looking for: play-services-basement.aar and fetches play-services-basement-11.0.1.aar instead? Could this be a naming convention or gradle issue?

SimbaClaws
  • 1,389
  • 2
  • 9
  • 13
  • Possible duplicate of [Ionic3 Build-Error: Could not find play-services-auth-base.aar (15.0.1)](https://stackoverflow.com/questions/50564090/ionic3-build-error-could-not-find-play-services-auth-base-aar-15-0-1) – Henry May 29 '18 at 07:32
  • I understand it is somewhat related because it is the same error message. But I think it would be better if the question was a general building failure question and not ionic related. Since this has to do with package building and could happen with a native app (or any framework really) as well. Hence I made the other topic. I also think this is why it is more broadly viewed, since people search for this type of topic title in a more general sense. – SimbaClaws Jan 27 '22 at 11:15

6 Answers6

357

jcenter() has had mirrors of some libraries (I guess they are doing intentionally) that should originally available through google() or maven() repositories. When gradle build works, for any library that is used in the project the first place to look for is the repository that is listed first in repositories {.. When the jcenter() mirror does not have the release (e.g com.google.android.gms:play-services-ads:15.0.1 for my case) your gradle is looking for, the build fails with such error.

So, jcenter() should be listed at the last place in repositories {.. parts as below.

   buildscript {
    ext.kotlin_version = '1.2.50'
    repositories {
        google()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        jcenter()
    }...

and

  allprojects {
    repositories {
        google()
        jcenter()
    }
  }
Muhamed Riyas M
  • 5,055
  • 3
  • 30
  • 31
Fio
  • 3,088
  • 2
  • 13
  • 23
  • 4
    This solved my problems with the "could not find ...aar" files after updating to 'com.google.gms:google-services:4.0.1'. Every time I try and update this or the Play Services version I seem to run into this type of obscure and frustrating problem. Thanks for ending a 3 hour hunt to resolve this issue! – Kyle Jul 08 '18 at 02:34
  • 11
    saying jcenter to be last place in cradle file is rescue my life :) – salih Aug 04 '18 at 12:36
  • 3
    this problom suddenly happend for me, Thank you so much ur solution help just with change order of jcenter() to the last one . – abadooz Oct 23 '18 at 07:28
  • 1
    just ran into this issue. – Hades Oct 24 '18 at 03:08
  • 2
    Thanks. Project was working fine and suddenly I ran into the same issue. Putting jcenter() to the last one solved the issue. – Lazy Ninja Oct 24 '18 at 05:13
  • `google()` is a [shortcut](https://docs.gradle.org/current/userguide/userguide_single.html#sub:maven_google) to `maven { url 'https://maven.google.com' }`. You don't need to write both. – wonsuc Oct 24 '18 at 05:46
  • But is this a best solution. Do I have to update the gradle file each time I remove platform and add it. Talking about building builds via cordova – DevSab Oct 24 '18 at 15:10
  • Also just ran into this issue. Thanks for saving us the trouble (L) – Simão Garcia Oct 25 '18 at 15:51
  • 1
    Thank you so much! Just going to throw in a few keywords for others having the same issue I was having. play-services-basement play-services-measurement-base jcenter not found cordova location build.gradle 15.0.2 – Terren Oct 27 '18 at 00:26
  • same here i had google right after thank you for the quick fix! – paul590 Nov 01 '18 at 00:40
  • 1
    Just changed the jcenter() to last solved my problem. Thank you so much – Inaccessible Nov 05 '18 at 05:26
  • 1
    I don't understand why this error raised before looking in the next repository? If the next repository have what my project need I expect the gradle to look in the next one and find it and not raise an error – RafaelJan Dec 07 '18 at 14:09
  • I agree with RafaelJan that this should definitely work differently. It seems rather obtrusive that a build would fail regardless of it having all of the repositories it should be able to search through... What else is the point of having multiple repositories in there? – SimbaClaws Jan 27 '22 at 10:52
14

This is crazy!!! I faced the same issue. The builds were working fine and then suddenly started to fail with the same issue. I tried the suggestions above but it didn't work for me. Finally, this is what worked for me:

Update to latest firebase dependencies:

implementation 'com.google.firebase:firebase-core:16.0.4'
implementation 'com.google.firebase:firebase-ads:17.0.0'

also, the ads services:

implementation 'com.google.android.gms:play-services-ads:17.0.0'

Note: with play-services-ads:17.0.0, it mandatory to add the following in the Manifest file, otherwise application crashes on opening.

<application>
    <!-- Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713 -->
    <meta-data
        android:name="com.google.android.gms.ads.APPLICATION_ID"
        android:value="[ADMOB_APP_ID]"/>
</application>
user846316
  • 6,037
  • 6
  • 31
  • 40
  • This worked for me. I highlighted over all of the gradle depenencies giving me problems and there was a newer version available. Changed them to the newest version and it worked. – Chris Deck Oct 24 '18 at 00:20
  • I had to update all of the firebase dependencies to get it building successfully. – Jason Oct 24 '18 at 03:30
  • 1
    This seems to be the "current" correct answer. The accepted answer of re-ordering things just doesn't seem to matter in many cases. – Josh Nov 01 '18 at 17:00
  • I understand that it is a matter of updating packages, because they will ultimately decide which packages and with which names to download from the repositories. Is it the package maintainer that should update their references when a repository decides to change their package name though? If that would be the case, that would mean each time either one of the repo's decide to change their package names, a package maintainer would have to obsolete ALL of their previous versions and move to a 'current' version that does work. The reason I don't accept this answer is exactly because I dissagree – SimbaClaws Jan 27 '22 at 10:58
  • I'd rather see the ability to allow for multiple repositories to be searchable, rather then hard failing on the single first one in the list. This way you'd be able to support older packages with different naming schemes by entering alternate sources. (Perhaps you'd even want to host your own repository with package names at some point for stability and self maintaining purposes?) I understand this means relying on older packages, which is bad. But in some cases you have a dependency issue which can not be solved because of outdated software. Supporting legacy systems should be supported IMO. – SimbaClaws Jan 27 '22 at 11:06
6

UPDATE #2 2018/05/29

The issue looks to be fixed gone now, and I'm still using the same gradle configs. But I did these steps a while ago I'm not sure if these did anything or if this is a server-side issue and it got fixed/updated recently. I just noticed the issue was gone after I did the following steps:

  1. Add the following in project-level gradle.build's buildscript > repositories and allprojects > repositories.

    • google()
    • maven { url 'http://jcenter.bintray.com' }
  2. Change the google-services classpath to
    classpath com.google.gms:google-services:4.0.1'

  3. Sync Project with Gradle Files



UPDATE #1 2018/05/29

I got around the error by downgrading my firebase dependencies to ~12.0.0 in the app-level gradle. But this will severly impact the app, still looking around for more feasible workarounds.



    apply plugin: 'com.android.application'
    apply plugin: 'io.fabric'
    ...
    compile 'com.google.firebase:firebase-core:12.0.0'
    compile 'com.google.firebase:firebase-database:12.0.0'
    compile 'com.google.firebase:firebase-storage:12.0.0'
    compile 'com.google.firebase:firebase-auth:12.0.0'
    compile 'com.google.firebase:firebase-crash:12.0.0'
    ...




Same here, I have experienced the same issue described by @SimbaClaws. Everything was compiling smoothly until I faced the same issue yesterday.

I have the following codes in my project-level build.gradle,



    // Top-level build file where you can add configuration options common to all sub-projects/modules.

    buildscript {
        repositories {
            jcenter()
            maven {
                url 'https://maven.fabric.io/public'
            }
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:2.3.3'

            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
            //classpath 'com.google.gms:google-services:3.0.0'
            classpath 'com.google.gms:google-services:3.2.1'
            classpath 'io.fabric.tools:gradle:1.25.1'
        }
    }

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

    task clean(type: Delete) {
        delete rootProject.buildDir
    }


And the following codes for the app-level build.gradle



    apply plugin: 'com.android.application'
    apply plugin: 'io.fabric'

    android {
        compileSdkVersion 26
        buildToolsVersion "26.0.1"
        defaultConfig {
            applicationId "my.secret.application"
            minSdkVersion 16 // 19
            targetSdkVersion 26
            versionCode 1
            versionName "5.0.204"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
            exclude group: 'com.android.support', module: 'support-annotations'
        })

        compile 'com.google.firebase:firebase-core:15.0.2'
        compile 'com.google.firebase:firebase-database:15.0.0'
        compile 'com.google.firebase:firebase-storage:15.0.2'
        compile 'com.google.firebase:firebase-auth:15.1.0'
        compile 'com.google.firebase:firebase-crash:15.0.2'
        compile 'com.android.support:appcompat-v7:26.+'
        compile 'com.android.support:design:26.+'
        compile 'com.android.support:recyclerview-v7:26.+'
        compile 'com.android.support.constraint:constraint-layout:1.0.2'
        compile 'de.hdodenhof:circleimageview:2.2.0'
        compile 'com.android.support:palette-v7:26.+'
        compile 'com.android.support:support-v4:26.+'
        compile 'com.android.support:cardview-v7:26.+'
        compile 'com.github.bumptech.glide:glide:3.7.0'
        compile 'org.greenrobot:eventbus:3.1.1'
        testCompile 'junit:junit:4.12'
        compile 'com.crashlytics.sdk.android:crashlytics:2.9.1'
    }


    apply plugin: 'com.google.gms.google-services'


Can anyone advise if I missed anything? I'm also still looking around for possible workarounds and answers. TIA!

raiser00
  • 452
  • 4
  • 15
2

Had same issue, for me none of the answers mentioned here worked. So I just updated dependencies in the gradle file and whichever dependency had com.google.gms: (kept them at same version example 16.0.0)

Swapnil Kadam
  • 4,075
  • 5
  • 29
  • 35
1

I have also experienced this issue. The root cause, I found out was that there inconsistent build Gradle version. In the Gradle Scripts repository "if I can call it that " there are two build gradle modules. The build.gradle (Project: name of app) and the build.gradle (Module: app). Make sure that classpath 'com.android.tools.build:gradle:3.2.1' in dependencies is using the latest and same version of the tool. Inconsistencies result in issues with the build.

George
  • 2,865
  • 6
  • 35
  • 59
0

In my case just added www earlier url was like url "https://jitpack.io/" after this added www started working for me. In other repositories also try to add explicit URLs.

maven {
            url "https://www.jitpack.io/"
        }
aNiKeT
  • 96
  • 1
  • 5