Gradle构建工具为什么找不到play-services-tasks.aar?

25
今天突然在Android Studio中运行我的应用程序时遇到了错误。
它是:
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

我没有更改gradle文件,但它突然出现了。我的上一个构建几分钟前成功执行。

为什么它找不到play-services-tasks.aar,它是com.google.android.gms:play-services-tasks:15.0.1的一部分?

已尝试的步骤:

我检查了gradle文件中是否包含所有存储库,并且目前都是正确的。

为什么突然出现这个错误?

我还将此链接https://jcenter.bintray.com/com/google/android/gms/play-services-tasks/15.0.1/play-services-tasks-15.0.1.aar复制到浏览器中,但它工作得很好,也就是说,我得到了“文件下载”对话框。


我的Gradle文件

  • 应用程序级别

    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'
    
  • 项目级别

  • 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
    }
    
8个回答

45

进行以下更改后,错误消失了:

  1. 在应用程序 build.gradle 文件中的 repositories 中删除 maven { url 'https://maven.google.com' }
  2. 在顶层 build.gradle 的 allprojects/repositories 中添加 maven { url 'https://maven.google.com' } 作为第一个条目
  3. 将所有 play-services 和 firebase 依赖项更改为最新版本。
  4. 将 google-services 插件的版本更改为 classpath 'com.google.gms:google-services:4.0.1'

4
似乎很疯狂,但这对我也起作用了... 只需要1或2个就可以解决问题(我遇到了另一个 Google 依赖项的问题)。 - iGio90
2
@IvanRigamonti 请问您能否解释一下这个重新排序的方法是如何解决这个问题的?有没有任何技术上的解释? - RagAnt
1
@LordCommander 我假设Gradle根据build.gradle文件中的顺序加载存储库。因此,在我的情况下,在进行所描述的更改后,它首先查找Google的maven repo中的依赖项,然后在jcenter()和最后在google()中查找: “allprojects { repositories { maven { url 'https://maven.google.com' } jcenter() google() } }” 我只能猜测另外两个存储库中的一个尚未更新依赖项。 - Ivan Rigamonti
2
[google()] 是自 Gradle 4.x 版本以来添加 Maven 仓库的官方方式。 - OneCricketeer
1
这个可以工作。但是这样做根本不好。只需要进行一些简单的更改,你就需要费尽心思让它正常运行。 - Somir Saikia
显示剩余9条评论

27

8
在我的情况下:
allprojects {
    repositories {
        google()
        jcenter()
    }
}

解决了我的问题

  • 在我的旧配置中只有"jcenter()"
  • 第一行jcenter(),第二行google()不起作用

2
对于我的情况,我从应用 gradle的repositories中删除了mavenCentral(),并将maven { url 'https://maven.google.com' }移动到Ivan Rigamonti上面建议的项目 gradle的第一位置。不需要更新Firebase依赖项。

1
改变
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'

在我的情况下,它有效!


1
我今天遇到了同样的问题。之前一切正常,也许这是临时的 Google 服务器问题。
对我有用的解决方案是使用旧版本的 google-play-services:
implementation 'com.google.android.gms:play-services-maps:11.4.2'

如果我只更改地图的版本代码,那么我必须在所有谷歌播放服务中更改版本代码... 如果不这样做,我将会遇到版本冲突。 - RagAnt

0

如果你们遇到了像build.gradle error , Failed to resolve: common这样的错误 build.gradle error , Failed to resolve: common

那么请在Project build.gradle中的allprojects范围内的repositories范围中添加以下行:

line :

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

例子

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

0

谷歌在服务器端更改了包的命名约定,这可能是原因吗?

我现在遇到了与不同的Play服务包相同类型的问题。

即play-services-basement.aar...

我在思考...

Could not find play-services-tasks.aar

这意味着它正在寻找名为play-services-tasks.aar的文件。

而在服务器上,该文件被称为:

play-services-tasks-15.0.1.aar

我认为这可能是gradle问题,文件命名不正确,或者是服务器端问题,文件命名不正确。

如果我理解有误,请纠正我。

编辑:此问题应报告给jcenter.bintray.com,因为他们在服务器端有错。切换到Ivan Rigamonti提到的Maven存储库可能是一个解决方案,但我不确定ionic应用程序如何处理切换存储库。

编辑2:切换到maven存储库确实适用于ionic。对于ionic,我所做的就是通过将jcenter()放在buildscript存储库和allprojects存储库内的maven()下面来修改build.gradle。


1
是的,我注意到链接是有效的,但我也看到gradle中命名的文件与URL中的文件名不同,这可能是为什么会出现这个问题的原因?基本上,在gradle中未将版本追加到文件末尾... - SimbaClaws
2
我自己也不确定该怎么做。我想这可能是谷歌那边需要修复的问题?我只是在猜测,没有真正提供解决方案,而是根据我认为正在发生的事情扩展了问题。根据查看此主题的人数,我猜测现在有更多的人遇到了这个问题。 - SimbaClaws
1
是的,但是针对不同的包,play-services-basement.aar。尽管URL有效,但错误仍然存在。 - SimbaClaws
2
我认为很多开发人员都遇到了这个问题。 - RagAnt
1
我认为存储库(服务器端)存在一些问题,因为已经有多次报告了相同的错误。 - Pl4yeR
显示剩余3条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接