Android Studio无法解析常见的符号

cda*_*ung 6 android android-studio

我仔细遵循了从Eclipse到Android Studio的迁移指南,我得到的唯一错误是"无法解决符号常见问题",并且正在以下行中发生:

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
Run Code Online (Sandbox Code Playgroud)

有谁知道为什么会发生这种情况?

eti*_*nne 1

构建工具 (gradle) 找不到定义相关类的 google_play_services 库。更新你的 build.gradle 文件,以便它找到库(在正确的路径):

[编辑 2:从 6.5 开始,您可以有选择地添加所需的 Google Play 服务 API ]

dependencies {
    compile 'com.google.android.gms:play-services-base:9.4.0'
    compile 'com.google.android.gms:play-services-XXX:9.4.0'
}
Run Code Online (Sandbox Code Playgroud)

[编辑:更新的方法,现在提供“本机”支持]

打开 SDK Manager,下载并安装 Google Play Services 和 Google Repository 编辑 build.gradle 添加:

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

[旧方法]

检查 google-plays-services 是否是您项目中的模块,并且其 build.gradle 包含:

dependencies {
    compile files('libs/google-play-services.jar')
}
Run Code Online (Sandbox Code Playgroud)

在你的模块 build.gradle 中:

dependencies {
     compile project(':google-play-services')
}
Run Code Online (Sandbox Code Playgroud)