【问题标题】:Import com.google.android.gms.location.LocationServices, can't update location services导入com.google.android.gms.location.LocationServices,无法更新定位服务
【发布时间】:2015-01-09 17:03:38
【问题描述】:

我正在尝试测试 LocationService 示例,如http://developer.android.com/training/location/retrieve-current.html 我陷入了与

非常相似的错误

Can't Import com.google.android.gms.location.LocationServices

但我无法解决。

我安装了 Google Play 服务,其版本(在我的 Android SDK 管理器中)是 17。我知道最新版本是 19,但我无法从 SDK 管理器更新版本,我找不到这样做的任何选项.

在我的代码中:

import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;

前两个很好,第三个正在获取:

导入....无法解析

2015 年 12 月 1 日编辑

我正在使用 Eclipse。

【问题讨论】:

    标签: android


    【解决方案1】:

    您需要将 Google Play Services 库编译到您的项目中。

    如果您使用的是 AndroidStudio:

    打开build.gradle 并给你dependencies 标签添加这个:

    compile 'com.google.android.gms:play-services:6.+'
    

    所以它看起来像:

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.google.android.gms:play-services:6.+'
    }
    

    使用新的 Play Services 库,您可以选择性地编译 API(您可能不需要整个库,只需要其中的一部分)。你会去:

    compile 'com.google.android.gms:play-services-location:6.+'
    

    更多关于选择性编译here.

    【讨论】:

    • 谢谢,我使用的是 Eclipse,我使用 File >> Import >> Existing Android code into workspace 导入了谷歌库,然后我将这些库项目作为依赖项添加到我的项目中使用 项目属性 。是否也可以在 Eclipse 中选择性地编译 Google Play Services 库?我有点困惑...
    【解决方案2】:

    我解决了我的问题,但我不知道具体如何...

    首先我运行 Help >> Check for Updates

    这样做之后,我从 SDK Manager 更新了 Android SDK ToolsAndroid SDK Platform Tools,然后 Google Play Services 的版本变成了 22(之前是 17)。

    然后我的项目旁边有一个红色感叹号......和一个错误提示

    Google-play-services_lib Unable to resolve target 'android-9
    

    我从我的 Package Explorer 中删除了 google-play-services_lib,然后使用 Import >> Existing Android Code Into Workspace

    重新添加库

    我不知道究竟是什么操作解决了这个问题……我做了很多尝试……

    重要

    更新 SDK 后出现错误提示

    This Android SDK requires ADT version 23.0.0 or above.
    

    所以基本上我卸载了 ADT(版本是 22.x),包括:

    • Android Traceview
    • Android 层次结构查看器
    • Android 开发工具
    • Android DDMS
    • OpenGL ES 的跟踪器

      并安装版本 23 这样做

      1. 选择帮助 > 安装新软件 2.使用:p2repo - https://dl-ssl.google.com/android/eclipse/
      2. 选择开发者工具并下一步
      3. 接下来,接受许可协议*并完成

    这里提到[[This Android SDK requires ADT version 23.0.0 or above. Current version is 22.6. Please update ADT to the latest version?

    【讨论】:

      猜你喜欢
      • 2014-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-04
      • 2014-12-05
      • 2018-07-31
      相关资源
      最近更新 更多