【问题标题】:Getting started with Google Play Services, Cannot Resolve Symbol开始使用 Google Play 服务,无法解析符号
【发布时间】:2018-04-11 11:24:34
【问题描述】:

我正在使用 gradle 2.2 和 Google Play Services 12.0.1 开发一个 Android Studio 项目。我现在正在尝试从 Google Play 服务中添加功能。

问题是我无法导入 Google Play 服务库。当我尝试以下行时。

import com.google.android.gms.games.Games;

或任何类似的我得到“无法解析符号游戏”,Android Studio 建议“将库 <...> 添加到类路径”,但这似乎并没有改变任何东西。

到目前为止我做了什么

我开始关注this setup guide。这只是说更新你的 build.gradle。我的顶级 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"
      < ... >
      compile "com.google.android.gms:play-services-games:12.0.1"
    }
 }

我还确保 buildscript 部分包含 maven 链接。我还检查了是否从 SDK 管理器的“SDK 工具”窗格安装了 Google Play 服务。除此之外,我还在项目结构 -> 模块 -> 依赖项中添加了正确版本的播放服务作为依赖项。有人建议在早期的 Stack Overflow 问题上添加

<meta-data android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

到 AndroidManifest 可能会有所帮助,所以我的 Manifest 看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="wizard_team.wizards_tale" >

<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="27" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/GdxTheme" >
    <activity
        android:name="wizard_team.wizards_tale.AndroidLauncher"
        android:label="@string/app_name" 
        android:screenOrientation="landscape"
        android:configChanges="keyboard|keyboardHidden|navigation|orientation|screenSize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <meta-data android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

</application>

我在重新同步时没有收到任何错误消息,并且我多次尝试更新和重新启动 Android Studio。我也尝试过“使 chaches/restart 无效..”。

在我搜索 Google 的过程中,我发现有几个人遇到了同样的问题,我尝试了他们的解决方案,但没有任何效果。我花了很长时间解决这个问题,有人有什么建议吗?

【问题讨论】:

  • 重新检查关于哪个 build.gradle 的说明 - 似乎应该在应用级 build.gradle 中指定播放服务。
  • 我建议您首先尝试使用 QuickStart,它可以非常快速地使其发挥作用。 developers.google.com/gmail/api/quickstart/android
  • 已尝试将依赖项移动到应用级 build.gradle,没有变化。
  • 您可以参考这个link,它建议将google play-services 更新到较新的版本。还要确保在 SDK 管理器中安装了“Google Repository”。同样,这个forum 建议做gradlew cleangradlew build
  • 我也通过 Google Analytics(分析)服务得到了这个。试图追踪一个谷歌问题。或者一些解决方案。我已将 maven google repo 和 google() 添加到 build.gradle 文件的所有不同部分,但没有成功。 @Gotiasits 该快速入门指南正在使用旧版本的 google play 服务。我注意到他们的很多文档和示例都有些过时了。

标签: java android google-play-services google-play-games


【解决方案1】:

解决了。由于我没有太多创建应用程序的经验,我尝试将 google play 服务导入我的应用程序的核心模块部分。对于其他刚入门的人,像这样的 android 特定代码应该放在 android -> java -> [package-name] 中。

可能看起来微不足道,但作为使用this 设置工具的初学者,这个问题让我找了好几个小时。

【讨论】:

    猜你喜欢
    • 2017-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-20
    • 2013-11-15
    • 1970-01-01
    相关资源
    最近更新 更多