java - 无法使用 gradle 解决 IntelliJ Idea 中的 : com. google.android.gms:play-services

标签 java android intellij-idea gradle libgdx

我正在尝试在 IntelliJ Idea 中将 Google Play 服务添加到我的 libGDX 项目中。我已按照此处的设置指南进行操作: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'
    }
}

然后我尝试在 Idea 中同步我的 gradle 项目,只是为了得到“无法解决”错误。

好吧,设置指南还说“确保每次更新 Google Play 服务时都更新此版本号”,但问题是似乎几乎不可能找到该版本号:我的 Google Play 服务 SDK 版本根据Android SDK 管理器是“43”,到目前为止,我无法将此类“11.2.0”或任何典型版本字符串与“43”版本号相关联。并不是说设置指南对此只字未提。

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

Android SDK Manager Project Structure

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

欢迎提出任何想法。

提前致谢!

最佳答案

我在项目级 build.gradle 中将 jcenter() 放在 google() 之前时遇到了问题。当我更改顺序并将 google() 放在 build.gradle 中的 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
}

关于java - 无法使用 gradle 解决 IntelliJ Idea 中的 : com. google.android.gms:play-services,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45692460/

相关文章:

java - 如何将 sqlite 值填充到微调器中

java - 方法签名的代码检查

java - 如何修复 IntelliJ 插件中的 "connection refused"异常

java - spring mvc和spring boot之间web开发我应该学习哪一个

java - 使用 Tycho 在同一项目中进行源代码和测试源代码

java - 如何创建我自己的文件扩展名,如 .odt 或 .doc?

java - 保护sqlite数据库-android

Android - 关闭 AlertDialog 后清除值

intellij-idea - 是否有包含此信息的 IntelliJ/Gradle 日志?

java - 使用索引在 arraylist 的 arraylist 中添加元素