26

Today suddenly, I got an error when I tried to run my app in Android studio.

It is:

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

gradle_build_error

I didn't change anything in the gradle file but it appeared suddenly. My previous build executed successfully some minutes ago.

Why it can't find play-services-tasks.aar which is the part of com.google.android.gms:play-services-tasks:15.0.1

Steps taken:

I checked whether I included all repositories in the gradle files and all are correct so far.

Why does this error occur all of a sudden?

I also copied this link https://jcenter.bintray.com/com/google/android/gms/play-services-tasks/15.0.1/play-services-tasks-15.0.1.aar into the browser but it's working fine, that is, I got "File Download" dialog.


My Gradle Files

  • App level

    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 26
        buildToolsVersion "26.0.2"
        defaultConfig {
            applicationId "mekanic24assistantapplication.heba.mekanic24.com.mekanic24assistantapplication"
            minSdkVersion 14
            targetSdkVersion 26
            versionCode 13
            versionName "2.1"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
            multiDexEnabled true
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    
    
        dexOptions {
            incremental true
            javaMaxHeapSize "4g"
        }
    
    //    err Android Gradle Duplicate files copied in APK META-INF/license.txt
    
        configurations.all {
    
            resolutionStrategy {
                force 'com.android.support:support-v4:26+'
                force 'com.android.support:support-annotations:26+'
    
    
            }
    
        }
    
    
        packagingOptions {
            exclude 'META-INF/DEPENDENCIES.txt'
            exclude 'META-INF/LICENSE.txt'
            exclude 'META-INF/NOTICE.txt'
            exclude 'META-INF/NOTICE'
            exclude 'META-INF/LICENSE'
            exclude 'META-INF/DEPENDENCIES'
            exclude 'META-INF/notice.txt'
            exclude 'META-INF/license.txt'
            exclude 'META-INF/dependencies.txt'
            exclude 'META-INF/LGPL2.1'
        }
    
    }
    
    dependencies {
        compile fileTree(include: ['*.jar'], dir: 'libs')
        androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
            exclude group: 'com.android.support', module: 'support-annotations'
        })
        //   compile 'com.android.support:appcompat-v7:26.3.1'
        compile 'com.android.support:appcompat-v7:26+'
        compile 'com.android.support:design:26+'
        compile 'com.android.support:recyclerview-v7:26+'
        compile 'com.android.support:cardview-v7:26+'
        compile 'com.android.support.constraint:constraint-layout:1.0.2'
        androidTestCompile 'com.android.support:support-annotations:26+'
        testCompile 'junit:junit:4.12'
        //   compile 'com.android.support:appcompat-v7:26.3.1'
        compile 'com.github.markushi:circlebutton:1.1'
        //  compile 'com.android.support:design:26.3.1'
        compile 'com.android.volley:volley:1.0.0'
        compile 'com.google.android.gms:play-services-base:15.0.1'
        compile 'com.android.support:multidex:1.0.1'
        compile 'com.firebase:firebase-client-android:2.5.2'
        compile 'com.google.firebase:firebase-core:15.0.2'
        compile 'com.google.firebase:firebase-messaging:15.0.2'
        compile 'com.google.firebase:firebase-database:15.0.0'
        compile 'com.wang.avi:library:2.1.3'
        compile 'de.hdodenhof:circleimageview:2.2.0'
        compile 'android.lib.recaptcha:reCAPTCHA:2.0.0'
        compile 'com.google.android.gms:play-services-safetynet:15.0.1'
        compile 'com.google.android.gms:play-services-maps:15.0.1'
        compile 'com.google.android.gms:play-services-places:15.0.1'
        compile 'com.google.android.gms:play-services-location:15.0.1'
    
        compile 'com.squareup.picasso:picasso:2.5.2'
        testCompile 'junit:junit:4.12'
        compile 'com.anjlab.android.iab.v3:library:1.0.38'
        compile files('libs/mail.jar')
        compile files('libs/additionnal.jar')
        compile files('libs/activation.jar')
        compile 'com.jakewharton:butterknife:8.8.1'
        annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
        compile 'com.yarolegovich:lovely-dialog:1.1.0'
        compile 'com.mobsandgeeks:android-saripaar:2.0.3'
        compile 'com.github.stfalcon:smsverifycatcher:0.3.1'
        compile 'ch.acra:acra:4.9.0'
        //TODO:  Apache 2.0 license https://github.com/ACRA/acra
        compile 'com.google.android.gms:play-services-ads:15.0.1'
        compile 'com.github.luongvo:GmailBackground:2.0.2'
    
    }
    apply plugin: 'com.google.gms.google-services'
    
  • Project Level

    buildscript {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
        maven {
            url "https://dl.bintray.com/android/android-tools"
        }
    
        maven { url "https://jitpack.io" }
        google()
    
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.2'
    
        classpath 'com.google.gms:google-services:3.2.0'
    }
    }
    
    allprojects {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
        maven {
            url "https://dl.bintray.com/android/android-tools"
        }
    
        maven { url "https://jitpack.io" }
        google()
    
    }
    }
    
    task clean(type: Delete) {
    delete rootProject.buildDir
    }
    
Floern
  • 33,559
  • 24
  • 104
  • 119
RagAnt
  • 1,064
  • 2
  • 17
  • 35

8 Answers8

46

After doing the following changes the error disappeared:

  1. Removed maven { url 'https://maven.google.com' } from repositories in app build.gradle.
  2. Added maven { url 'https://maven.google.com' } as first entry in allprojects/repositories in top level build.gradle
  3. Changed all play-services and firebase dependencies to the latest versions
  4. Changed version of google-services plugin to classpath 'com.google.gms:google-services:4.0.1'
Roman Nazarevych
  • 7,513
  • 4
  • 62
  • 67
Ivan Rigamonti
  • 696
  • 5
  • 7
  • 4
    seems crazy, but this worked for me too... 1 or 2 did the job (having problems with another google dep) – iGio90 May 28 '18 at 11:16
  • I'm working on an ionic application (using cordova), so I don't know where this (allprojects/repositories) folder would be. Could you point me in the right direction? – bvx89 May 28 '18 at 11:18
  • @bvx89 Sorry, I don't know how ionic solves dependencies. In my solution I assume that Gradle resolves repository urls sequentially top to bottom. This would mean, that Gradle looks first in Google's maven repository. But that's just my assumption. Try to change your settings to have the link to Google's maven repo first. Hope this helps. – Ivan Rigamonti May 28 '18 at 11:23
  • @bvx89You can open the platform folder via android studio. There you see the gradle files under gradle scripts. Somehow the issue was solved for me by rearranging the repositorie ordering in all sub gradle files as described here. After this, normal cordova build is working again. – Robert May 28 '18 at 11:36
  • @IvanRigamonti .. Worked for me. I just executed steps 1 & 2 and it worked as a charm. Thank you very much . You saved my time – RagAnt May 28 '18 at 11:38
  • Actually the weird thing is, it did not work for me the first couple of times. Then after some resets and retries it suddenly works again (even though, some of the edited files are reset by cordova again all the time). Also, I don't need to adjust any versions. Strange issue. – Robert May 28 '18 at 11:42
  • 2
    @IvanRigamonti .. Will you please explain how this reordering method solved this issue? Any technical explanations are there ? – RagAnt May 28 '18 at 11:43
  • @Frank, I found out what Ivan Rigamonti meant and did steps 1 & 2. It worked right away. I see that SimbaClaws is suggesting rearranging the repositories as a fix, but I haven't tried it myself. I think the best option is to just do the hack until bintray is fixed, and revert back afterwards. – bvx89 May 28 '18 at 12:12
  • 1
    @LordCommander I assume that Gradle loads repositories according to the sequence in the build.gradle file. Thus, in my case after the described change it looks first for dependencies in Google's maven repo and then at jcenter() and last at google(): 'allprojects { repositories { maven { url 'https://maven.google.com' } jcenter() google() } }' I can only guess that one of the two other repos had not yet updated dependencies. – Ivan Rigamonti May 28 '18 at 13:14
  • 2
    [`google()` is the official way to add that maven repo as of Gradle version 4.x](https://stackoverflow.com/q/46467561/2308683) – OneCricketeer May 28 '18 at 14:49
  • @IvanRigamonti Does the order not matter for Gradle plugin 2.x+..Because this error is new to me – MrRobot9 May 28 '18 at 19:15
  • 1
    This worked. But this is not at all good. Something such simple changes and you need to bang your head to get it working. – Somir Saikia May 29 '18 at 03:52
  • Thanks for the solution.. Just moving `google()` line to the top magically worked!! – Meet Vora Jul 18 '18 at 09:51
  • Thanks @IvanRigamonti : you save me :) – Pamungkas Jayuda Nov 18 '18 at 15:56
27

The fix is to put google url above jcenter() in your repository list in gradle.

Here's the issue: https://issuetracker.google.com/issues/80362794

Sergio
  • 1,370
  • 11
  • 12
8

in my case:

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

solves my problems

  • in my old configuration was only "jcenter()"
  • first line jcenter(), second line google() doesn't work
2

For my case I removed mavenCentral() from app gradle repositores and moved maven { url 'https://maven.google.com' } to the first positionin in project gradle as Ivan Rigamonti suggested above. No Firebase dependecies update needed.

(this should be a comment, but I don't have enough reputation)

Francis
  • 6,788
  • 5
  • 47
  • 64
1

I am getting the same issue today. It was working fine until now. Maybe it's a temporary Google servers issue.

The solution that works for me is using an older version of google-play-services:

implementation 'com.google.android.gms:play-services-maps:11.4.2'
adidami
  • 11
  • 1
  • 4
  • If I change version code for just maps then I have to change version code in all google play services ... If not then I will led to version conflict – RagAnt May 28 '18 at 09:56
1

Change

compile 'com.google.android.gms:play-services-safetynet:15.0.1'
compile 'com.google.android.gms:play-services-maps:15.0.1'
compile 'com.google.android.gms:play-services-places:15.0.1'
compile 'com.google.android.gms:play-services-location:15.0.1'

to

compile 'com.google.android.gms:play-services-safetynet:16.0.0'
compile 'com.google.android.gms:play-services-maps:16.0.0'
compile 'com.google.android.gms:play-services-places:16.0.0'
compile 'com.google.android.gms:play-services-location:16.0.0'

Is my case, it works!

0

Could it be that google changed the naming conventions of the packages on the server side?

I'm experiencing the same sort of issue with a different play services package just now.

Namely play-services-basement.aar...

I'm thinking that

Could not find play-services-tasks.aar

Means it's looking for the file named as play-services-tasks.aar

While on the server this file is called:

play-services-tasks-15.0.1.aar

I'm thinking this is either a gradle issue where files aren't named correctly or a server side issue where files aren't named correctly.

Please correct me if I'm mistaken here.

EDIT: this issue should be reported to jcenter.bintray.com since they are the ones being at fault here at their server side. Switching to the Maven repository mentioned by Ivan Rigamonti could be a solution but I'm uncertain how ionic apps deal with switching repositories.

EDIT2: Switching to the maven repository does indeed work for ionic. All I had to do for ionic was to alter build.gradle by putting jcenter() underneath maven() inside of the buildscript repositories and allprojects repositories.

SimbaClaws
  • 1,389
  • 2
  • 9
  • 13
  • https://jcenter.bintray.com/com/google/android/gms/play-services-tasks/15.0.1/play-services-tasks-15.0.1.aar The link is working in broswer – RagAnt May 28 '18 at 09:54
  • 1
    yes I realised the link is working but I also see that the file named in gradle is different then the one in the url, which could be why it's comming up with this issue? Basically the version isn't appended to the end of the file in gradle... – SimbaClaws May 28 '18 at 09:57
  • I understand.. How can I change the filename in gradle? – RagAnt May 28 '18 at 10:05
  • 2
    I am uncertain myself what to do at this point. I'm thinking it's something that has to be fixed from google's end? I'm just hypothesizing here, I'm not really contributing an actual solution but rather extend the question based on what I think is happening. Based on how many people are viewing this topic I'm guessing more people are having this problem right now. – SimbaClaws May 28 '18 at 10:06
  • 1
    yes but for a different package, play-services-basement.aar Same symptoms though, the url works but the error remains. – SimbaClaws May 28 '18 at 10:11
  • I am very sad. I have to release this app before May 31st.. So it need to be fixed soon – RagAnt May 28 '18 at 10:13
  • 2
    I am thinking that lot of developers experiencing this issue – RagAnt May 28 '18 at 10:13
  • 1
    I think there are some problems with the repository (server side) since this same error has been reported multiple times – Pl4yeR May 28 '18 at 11:04
0

if you Guys Getting Error Like build.gradle error , Failed to resolve: common like this build.gradle error , Failed to resolve: common

then put below line in allprojects scope in repositories scope in Project build.gradle

line :

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

example

allprojects {
    repositories {
        maven { url 'https://maven.google.com' }
        jcenter()
        google()
    }
Vinesh Chauhan
  • 1,288
  • 11
  • 27