今天我将 Android SDK 组件更新到最新版本,不知何故整个 com.google.android.gms 包不见了。相反,只有 com.google.android.maps 的类与 gms 包中的类不同。这是谷歌的重大变化还是我做错了什么?我一直在使用 GoogleMap 和 LatLng 类来处理谷歌地图,现在我的项目中出现了错误。
6 回答
这是谷歌的重大变化还是我做错了什么?
com.google.android.gms
来自 Play Services SDK,您将其作为 Android 库项目附加到您的应用程序项目中。请检查您的环境以确保您拥有 Play Services 库项目的有效副本,并且您的应用程序项目仍然指向它。
First off, if you did not run any updates with Android SDK Manager make sure the google-play-services-lib' project is open in eclipse. If this doesn't fix your problem then proceed. Note: eclipse(v22.0.1-685705) will close google-play-services-lib project with a 'close unrelated projects' command. The google-play-services-lib project must be open.
I figured this problem out. Initially, you/I installed Google Play services in eclipse directly from the SDK Path, (SDK Path is displayed on the top left of Android SDK Manager). When you updated Google Play services with the Android SDK Manager it deleted the .project file and now eclipse can't find the 'google-play-services-lib' project and your development project fails to compile. :-(
Solution:
The basic ideal of this solution is to clean out the old 'google-play-services-lib' project in eclipse, which is now defunct and install a new one with the project copied from the SDK path.
Delete the old project:
In eclipse delete any 'google-play-services-lib' project. (In Eclipse see: Project properties-> Android -> Library.)
In In Eclipse see: Project properties-> Android -> Library delete the old entry for 'google-play-services-lib' project. This will most likely have an red 'X' on it.
Install a new one:
Follow the instruction from Google to install 'google-play-services-lib' project. These instruction specify to copy the project out of the SDK install folder; and then how to set up the projects.
http://developer.android.com/google/play-services/setup.html
Notes:
Your name for 'google-play-services-lib' may be different.
The key to remember is that Google play services is not a jar file. It is a project in eclipse. Your, development project references the google-play-services-lib project.
By copying the project folder from the SDK path to another location, this will keep the Android SDK Manager from deleting your eclipse .project file, and causing this problem. The draw back is if you would like to update google play services, you have to remember to do all the steps again.
您将需要 Google Play 服务 sdk。如果您使用 sdk for eclipse,您可以从 Android SDK Manager 安装它。
安装 Google Play 服务后,您可以从 ..\sdk\extras\google\google_play_services 文件夹将库项目导入您的 Workspace。清理并构建它。
现在您可以转到有问题的项目的属性并在 Android 部分选择库项目。
这应该工作!
当前库位于 Google 存储库中。要启用它,请确保您已使用 Android SDK Manager 下载它(一直到列表的最底部)。
如果使用 Android Studio,您可以通过向文件添加依赖项来添加 Google Play 服务以使用 Google Android Maps v2 build.gradle
。
dependencies {
compile 'com.google.android.gms:play-services:3.1.36'
}
对于android create project [...]
基于 ant CLI 的项目
类似于:如何在非 Eclipse Android 应用程序中正确包含支持库
我能找到的最好的是https://stackoverflow.com/a/30689979/895245:
- 在项目目录中复制粘贴
android-sdk/extras/google/google_play_services/libproject/google-play-services_lib
目录 cd
进入它并运行android update project -p . -t android-22
- 添加
<property name="android.library.reference.1" value="./google-play-services_lib"/>
到您的build.xml
.
android
您可以使用GUI 工具或使用此 CLI 方法安装 extras :从命令行下载 Android 支持库
如果你只是复制粘贴到项目.jar
的目录<sdk>/extras/google/google_play_services/libproject/google-play-services_lib/libs/google-play-services.jar
下libs/
,它会编译但在运行时会中断,因为 requiredres/values/version.xml
不包含在.jar
.