【问题标题】:Using Google Play Services as a dependency in gradle build在 gradle build 中使用 Google Play Services 作为依赖项
【发布时间】:2015-08-12 14:00:21
【问题描述】:

知道为什么 gradle 无法解析对 Google Play Services lib 的引用吗?

即使在我添加了一个依赖项并在Eclipse 中刷新了我的依赖项之后..

AdView cannot be resolved to a type

根项目内的目录列表。我用的是LibGdx,所以每个目标平台都是一个子目录(子项目)。

bob@laptop:~/git/game$ ls
android       core     gradle.properties  ios
build         desktop  settings.gradle    build.gradle

来自根项目gamebuild.gradle 的片段......

bob@laptop:~/git/game$ cat build.gradle | grep -A 25 ":android"
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-x86"
        compile "com.badlogicgames.gdx:gdx-box2d:$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.google.android.gms:play-services:7.8.99'
    }
}

最新版本的Google Play Services 下载到我的本地sdk ..

【问题讨论】:

  • apply plugin: "android" 大约在一年前被apply plugin: "com.android.application" 取代。您使用的是什么版本的 Gradle 和 Gradle for Android 插件?
  • 我使用libgdx,默认使用classpath 'com.android.tools.build:gradle:1.2.3'

标签: android eclipse gradle


【解决方案1】:

您可能没有正确的 Play 服务版本号。

尝试使用 7.5.0

【讨论】:

    【解决方案2】:

    我对@9​​87654321@ 一无所知。但是,您的构建过程似乎正在抑制构建错误和警告。除非apply plugin: "android" 指的是 Google 的 Gradle for Android 插件以外的东西,否则您至少应该收到一个警告,因为该名称已被弃用。更重要的是,您应该会收到关于未找到 compile 'com.google.android.gms:play-services:7.8.99' 作为依赖项的构建错误。

    安装您在 SDK 管理器屏幕截图中指向的内容(“Google Play 服务”)只会下载一个本地库项目,供 Eclipse(无 Gradle)使用。对于传统 Android 项目中对 com.google.android.gms:play-services 的 Gradle 依赖项,您需要安装 Google Repository 和 Android Repository。根据您的屏幕截图,您至少没有安装 Android 存储库。同样,libgdx 可能有一些与 Android 规范不同的奇怪处理方式。

    【讨论】:

      猜你喜欢
      • 2018-11-06
      • 1970-01-01
      • 2018-06-27
      • 1970-01-01
      • 2015-02-25
      • 2015-02-17
      • 2016-03-31
      • 2021-10-08
      • 1970-01-01
      相关资源
      最近更新 更多