Gradle找不到依赖项com.google.android.gms:play-services。

8
自从我将Android Studio升级到3.0.0后,我遇到了一个问题:我再也找不到com.google.android.gms:play-services了!在添加此依赖项后,当我尝试同步我的项目时,会出现以下消息:
Failed to resolve: com.google.android.gms:play-services-games:11.4.2

我可以点击“安装仓库并同步项目”,但是当我这么做时,我得到了这个消息:

Could not find dependency "com.google.android.gms:play-services-games:11.4.2"

我尝试搜索,但我发现的唯一解决方案是安装Google存储库,并将jcenter()添加到我的build.gradle文件中的存储库中。但我已经做过了!

有什么想法吗?

这是我的build.gradle文件:

buildscript {


    repositories {
        mavenLocal()
        mavenCentral()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
        classpath 'com.mobidevelop.robovm:robovm-gradle-plugin:2.3.1'


    }
}

allprojects {
    apply plugin: "eclipse"
    apply plugin: "idea"

    version = '1.0'
    ext {
        appName = "Glowee"
        gdxVersion = '1.9.7'
        roboVMVersion = '2.3.1'
        box2DLightsVersion = '1.4'
        ashleyVersion = '1.7.0'
        aiVersion = '1.8.0'
    }

    repositories {
        mavenLocal()
        mavenCentral()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        maven { url "https://oss.sonatype.org/content/repositories/releases/" }
    }
}

project(":desktop") {
    apply plugin: "java"


    dependencies {
        compile project(":core")
        compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
        compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"

    }
}

project(":android") {
    apply plugin: "android"

    configurations { natives }

    dependencies {
        compile project(":core")
        compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-arm64-v8a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64"
        compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"

        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-arm64-v8a"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86_64"

        compile "com.google.android.gms:play-services-games:11.4.2"
        compile "com.google.android.gms:play-services-ads:11.4.2"
        compile "com.google.android.gms:play-services-plus:11.4.2"

    }
}

project(":ios") {
    apply plugin: "java"
    apply plugin: "robovm"


    dependencies {
        compile project(":core")
        compile "com.mobidevelop.robovm:robovm-rt:$roboVMVersion"
        compile "com.mobidevelop.robovm:robovm-cocoatouch:$roboVMVersion"
        compile "com.badlogicgames.gdx:gdx-backend-robovm:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-ios"

        compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-ios"

    }
}

project(":core") {
    apply plugin: "java"


    dependencies {
        compile "com.badlogicgames.gdx:gdx:$gdxVersion"

        compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"

    }
}

tasks.eclipse.doLast {
    delete ".project"
}

你是否已经添加了 google() 仓库?https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#update_gradle - Kuffs
我已经完成了!我将它添加到了jcenter()存储库中,但我仍然收到相同的错误。 - Xavier P
请查看此链接:https://developer.android.com/studio/build/dependencies.html#google-maven - Kuffs
https://dev59.com/FV0a5IYBdhLWcg3wAEo3 - Anil
好的,我解决了!我把google()存储库添加到了buildscript范围中,现在我将其移到了allprojects范围中,现在它可以工作了,谢谢! - Xavier P
3个回答

15

我通过在build.gradle项目模块中添加google()仓库来解决了这个问题。

在此输入图片描述


虽然这个链接可能回答了问题,但最好在此处包含答案的基本部分并提供参考链接。如果链接页面更改,仅链接的答案可能会失效。-【来自审查】 - Saranjith
我附上了我的Project Build Gradle的截图。他所需要做的就是在repositories {}中添加"google()",这就是截图所告诉他的(或者说是我如何实现的)。 这是一个指向imgur的链接,就这些了@Saranjith。 - other Tall guy
9
我有这个问题,而且我的存储库中有 google() - salmanseifian
在jcenter()之前的第一行中加入google(),@SalmanSeifian。 - Borja

6

我曾经遇到过同样的问题,通过在build.gradle项目模块中添加google()仓库,我解决了这个问题。


0

我尝试使用 'google()',但它没有起作用。阅读了一些AndroidStudio的建议后,我发现要解决这个问题,我必须手动修改build.gradle文件,升级compileSdkVersion、minSdkVersion等... 我猜问题出现是因为我使用的东西与我拥有的minSdkVersion不兼容。


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