Android无法解析导入com.google

PPS*_*ein 17 android google-maps geolocation

我正在尝试按照以下链接http://developer.android.com/training/location/retrieve-current.html测试Android开发人员的LocationService示例.那时,错误消息显示以下5行" 无法解析导入com.google ".我真的很困惑如何解决这个问题.

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesClient;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.location.LocationClient;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;
Run Code Online (Sandbox Code Playgroud)

Man*_*aya 19

您需要在Eclipse中配置Google Play Services SDK并导入google play服务,因为库将解除此错误.

  • 如何以适当的方式将Google Play服务导入库? (15认同)
  • 菜单窗口 - > Android SDK Manager.在"额外内容"下找到"Google Play服务".如果未安装,请检查并安装.然后,在你的Eclipse项目中,转到你的Java Build Path,添加外部jar,然后找到google-play-services.jar,它位于你的android sdk中的某个地方(在我的情况下它是`android-sdk-linux/extras/google/google_play_services/libproject /谷歌播放services_lib/libs` (4认同)

Sit*_*thu 18

有一个更简单的解决方案.就我而言,我已经从几个来源得到了所有答案,但没有一个能直接回答我的问题.最后,我找到了一个示例应用程序源代码,当我导入源代码时,我发现从Google Play Service Library目录中添加库解决了它.Google Play Service Library位于(对于Windows用户)这里:

    \sdk\extras\google\google_play_services\libproject
Run Code Online (Sandbox Code Playgroud)

将库作为库项目导入Eclipse,并在实际项目中添加此库将修复它.

编辑:这家伙在他的教程上做了很多贡献,如何逐步使用Android谷歌地图v2和非常详细.它还包括如何使用Android Support包的片段backport.

    http://ddewaele.github.io/GoogleMapsV2WithActionBarSherlock/part1
Run Code Online (Sandbox Code Playgroud)


Big*_*low 10

假设您使用Eclipse.
右键单击您的项目 - > properties - > Android.
使用Google API代替标准Android.


mor*_*tzw 7

如果您使用的是Android Studio:

右键单击您的应用程序文件夹 - > 打开模块设置 - > 依赖关系 - >单击加号按钮 - >选择库依赖关系 - >搜索" 播放服务 " - >双击com.google.android.gms:播放-服务

确定并等待Gradle重建.


Par*_*thi 5

你可以用这种方式.首先是使用google-play-services库的密切项目.每当您将鼠标悬停在无法解析的com.google.android.gms导航栏上时,请选择弹出菜单底部,选择" Fix project setup"选项,如下所示.然后它会提示导入google-play-services库.

在此输入图像描述