无法解决:com.google.android.gms:使用gradle在IntelliJ Idea中播放服务

Fra*_*zoa 68 java android intellij-idea gradle libgdx

我正在尝试在IntelliJ Idea中为我的libGDX项目添加Google Play服务.我已按照此处的设置指南进行操作:https://developers.google.com/android/guides/setup

这看起来非常简单.我刚刚在相应的部分中将这些行添加到我的build.gradle中,所以现在看起来像:

project(":android") {
    apply plugin: "android"
    apply plugin: 'com.android.application'

    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-box2d-platform:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86"
        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:11.2.0'
    }
}
Run Code Online (Sandbox Code Playgroud)

然后我尝试在Idea中同步我的gradle项目,以获得"无法解决"错误.

好吧,设置指南还说"确保每次更新Google Play服务时都更新此版本号",但问题是找到该版本号几乎是不可能的:根据Android SDK我的Google Play Services SDK版本manager是"43",到目前为止,我无法将这样的"11.2.0"或任何典型的版本字符串与"43"版本号相关联.并非设置指南对此没有任何说明.

无论如何,我从与此相关的众多问题中尝试了很多事情但无济于事.具体来说,我必须指出我确实更新了我的Android SDK,我确信它是Idea正在使用的那个(我已经三次检查了这个......):

Android SDK Manager 项目结构

我正在使用API​​级别26,但无论如何其他定义确实使用Android SDK的相同目录.此外,我没有在这台笔记本电脑上安装任何其他Android SDK,所以毫无疑问,Idea只使用那个和那个.

任何想法都非常受欢迎.

提前致谢!

Mou*_*ssa 217

jcenter()之前google()在项目级build.gradle中提出了这个问题.当我更改顺序并在build.gradle google()之前jcenter()放置时,问题就消失了

这是我的最终build.gradle

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

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

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

task clean(type: Delete) {
    delete rootProject.buildDir
}
Run Code Online (Sandbox Code Playgroud)


Fra*_*zoa 79

我刚刚用11.0.0替换了版本11.2.0然后它似乎工作正常,所以这意味着11.2.0不包含在最新的Android SDK中.

因此,在与所有可用的分散文档进行斗争之后,我很有可能获得了这个文档(我猜它没有被Google编入足够高的索引):https: //developers.google.com/android/guides/releases

我引用那里:

Google Play服务11.2版本的亮点.Google Play服务依赖项现在可通过maven.google.com获得

现在,即使这不一定意味着它们不再适用于下载的SDK,似乎实际上就是这种情况.

无论如何,将google()添加到我的build.gradle不起作用(找不到,未定义,或其他......),所以我使用了一种不同的方法,我在上一篇文章中引用了这个方法:

https://developer.android.com/studio/build/dependencies.html#google-maven

我修改了我的build.gradle文件,将该行添加到allprojects/repositories,如下所示:

allprojects {
...
    repositories {
...
        maven { url "https://maven.google.com/"}
    }
}
Run Code Online (Sandbox Code Playgroud)

然后还在同一build.gradle文件的android部分:

project(":android") {
...
    dependencies {
...
        compile 'com.google.android.gms:play-services-ads:11.2.0'
    }
}
Run Code Online (Sandbox Code Playgroud)

这两行足以使Gradle同步没有问题.除了默认情况下已添加到我的libGDX项目中的插件之外,我不需要添加任何插件.

在那之后,我得到了一些不同的错误,但没有关于Gradle或依赖关系的错误.简而言之,JFTR:

首先,我有一个8的minSdkVersion.通过将它提高到14来解决.我想我可以在不支持14岁以下的所有设备的情况下生活.

其次,我对引用的dex上限有问题.我以前从未遇到过这个问题,但也许您已经注意到我使用的解决方案:而不是编译整个'com.google.android.gms:play-services'我只使用'com.google.android.gms :play-services-ads'这是我现在真正感兴趣的API.对于像这样的解决方案可能没用的其他特殊情况,本文档可以提供一些更好的见解:https://developer.android.com/studio/build/multidex.html

第三,即使在那之后,我在这里描述并回答了这个"巨型"问题:https://stackoverflow.com/a/26248495/1160360

就是这样.截至目前,一切都在构建,我的游戏终于展示了那些Admob横幅.

我想花了几个小时,这让我想知道我们最近使用的所有这些楼宇自动化系统是否值得他们增加的额外负荷.

我的意思是,五年前我第一次将Admob添加到应用程序中时,我只需下载一个.jar文件并将其放在我项目的目录中.这是非常明显的整个过程,从谷歌搜索"如何在我的Android项目中设置Admob"让我的应用程序显示Admob横幅花了我几分钟.我要把它留在这里,因为这不是进行这种辩论的地方.

尽管如此,我希望我自己的经验对其他人有用.

  • 我有一种感觉,这将在接下来的几周内得到很好的回答. (6认同)
  • 这是一个很好的答案:修复,文档,其他问题修复.只是让我从[相同的链接页面](https://developer.android.com/studio/build/dependencies.html#google-maven)添加它们更新了`maven {url"https://maven.google. com /"}`到`google()`.对于较低的Gradle版本[即低于Gradle 4.1],maven线是必需的.队友的欢呼声! (4认同)
  • 很棒的答案。谢谢! (2认同)

zsu*_*ary 15

将其添加到项目级build.gradle文件中:

repositories {
    maven {
        url "https://maven.google.com"
    }
}
Run Code Online (Sandbox Code Playgroud)

它对我有用


Ale*_*Vay 13

在我没有使用Android Studio一段时间后,我尝试解决这个问题几个小时,并且不知道更新.

重要的google()是,第一个项目repositories如下所示:

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
}
Run Code Online (Sandbox Code Playgroud)

不知何故google()是第二个项目jcenter(),所以一切都搞砸了,没有用.也许这有助于某人.


Ary*_*yan 10

Google Play服务SDK在里面Google Repository.

  1. 启动Intellij IDEA.

  2. 在"工具"菜单上,单击"Android">"SDK Manager".

  3. 更新Android SDK Manager:单击SDK Tools,展开Support Repository,选择Google Repository,然后单击OK.

目前的Google Repository版本为57.

更新后同步您的项目.

编辑

从版本11.2.0,我们将使用谷歌maven repo,所以在存储库标签中添加谷歌maven repo链接.从这里查看发行说明.

allprojects {
     ..
     repositories {
     ...
        maven {
            url 'https://maven.google.com'
            // Alternative URL is 'https://dl.google.com/dl/android/maven2/'
        }
     }
}
Run Code Online (Sandbox Code Playgroud)


Nou*_*MRI 6

更新的答案:

allprojects {
    repositories {
        google() // add this
    }
}
Run Code Online (Sandbox Code Playgroud)

并且不要忘记将gradle更新为4.1+(在gradle-wrapper.properties中):

distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
Run Code Online (Sandbox Code Playgroud)

来源:https://developer.android.com/studio/build/dependencies.html#google-maven